Context path
The context path is the prefix of a URL path that is used to select the context(s) to which an incoming request is passed. Typically a URL in a Java servlet server is of the format http://hostname.com/contextPath/servletPath/pathInfo, where each of the path elements can be zero or more / separated elements.

How to get ContextPath

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException 
{
  ServletContext servletContext = getServletContext();
  String contextPath = servletContext.getRealPath(File.separator);
  PrintWriter out = response.getWriter();
  out.println("<br/>File system context path (in TestServlet): " + contextPath);
}

Comments are closed.