Need to find the web application path
I created a web application usi开发者_Python百科ng netbeans and glassfish server. I created a new java file inside that application. I want to find the current application path in that java file.
You can get path information from a servlet with methods of HttpServletRequest class:
public class RequestInfoExample extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
String requestURI = request.getRequestURI();
String contextPath = request.getContextPath();
}
Javadoc information:
getRequestUri() - Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request...
getContextPath() - Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character...
精彩评论