getContextPath、getServletPath、getRequestURI的区别
假定你的web application名称为example,你在浏览器中输入请求路径:
https://localhost:8080/example/main/edit.jsp
则执行下面代码后打印结果如下:
System.out.println(request.getContextPath()); //result:/example System.out.println(request.getServletPath()); //result:/main/edit.jsp
System.out.println(request.getRequestURI()); //result:/example/main/edit.jsp System.out.println(request.getRealPath("/")); //result:D:\Tomcat 7\webapps\example\test