首页 > Web开发 > 详细

通过HttpServletRequest的request获取各种路径

时间:2017-05-17 00:05:11      阅读:310      评论:0      收藏:0      [点我收藏+]

System.out.println("getContextPath:"+req.getContextPath());
System.out.println("getServletPath:"+req.getServletPath());
System.out.println("getRequestURI:"+req.getRequestURI());
System.out.println("getRequestURL:"+req.getRequestURL());
System.out.println("getRealPath:"+req.getSession().getServletContext().getRealPath("image") );

 

输出结果为

getContextPath:/maven
getServletPath:/upload.do
getRequestURI:/maven/upload.do
getRequestURL:http://localhost:8080/maven/upload.do
getRealPath:D:\myecllipse\apache-tomcat-7.0.77-windows-x64\apache-tomcat-7.0.77\wtpwebapps\hcwproject\image

 

最后一个路径其实是工程在那个目录运行路径,不该路径默认会在工作空间

 

通过HttpServletRequest的request获取各种路径

原文:http://www.cnblogs.com/1736gerr/p/6864141.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!