getContextPath、getServletPath、getRequestURI 区别

版权声明:转载请注明来源 https://blog.csdn.net/genghaihua/article/details/88817924

若web application 名称为myweb,你在浏览器中输入请求路径: http://localhost:8090/myweb/main/welcome.jsp 

input output 关系如下:
1、 System.out.println(request.getContextPath()); 
result:/myweb

2、System.out.println(request.getServletPath()); 
result:/main/welcome.jsp 

3、 System.out.println(request.getRequestURI()); 
result:/myweb/main/welcome.jsp 

猜你喜欢

转载自blog.csdn.net/genghaihua/article/details/88817924