①.当前WEB应用的根路径(http://localhost:8080/contextPath/)
<servlet-mapping> <servlet-name>TestServlet</servlet-name> <url-pattern>/testServlet</url-pattern> </servlet-mapping>
②.WEB站点的根路径:(http://localhost:8080/)
<a href="<%=request.getContextPath()%>/index.jsp">进入网站</a>
<form action="<%=request.getContextPath()%>/testServlet" method="post"> </form>
response.sendRedirect(request.getContextPath()+"/index.jsp");
原文:http://www.cnblogs.com/realshijing/p/7880270.html