String contextPath = getServletContext().getContextPath(); response.getWriter().println("Context Path: " + contextPath);
String contextPath = getServletContext().getContextPath(); RequestDispatcher rd = getServletContext().getRequestDispatcher(contextPath + "/index.jsp"); rd.forward(request, response);This example retrieves the context path and uses it in a RequestDispatcher to forward the request and response to a JSP file. Package library: javax.servlet