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

 

posted @ 2017-05-05 11:35  Qingdong.Li  Views(122)  Comments(0Edit  收藏  举报