从request中获取项目的一些路径

论坛 期权论坛 脚本     
匿名网站用户   2020-12-20 09:58   66   0

无论是jsp还是项目进程要获取一些项目部署的实际路径或者项目的访问路径的,那么如何获取呢?

在web后端:

例如访问地址是:http://localhost:8080/test

request.getContextPath(); 获取到工程名称: /test

request.getServletContext().getRealPath("/"); 获取到实际路径例如:E:\java\tomcat7\apache-tomcat-7.0.55\wtpwebapps\test\

request.getRequestURI(); 获取到包含工程名的当前页面全路径:/test/action.do



jsp中获取路径:

String path=application.getRealPath(request.getRequestURI());

String realPath1 = "http://" + request.getServerName() + ":" + request.getServerPort() +request.getContextPath()+request.getServletPath().substring(0,request.getServletPath().lastIndexOf("/")+1);


String projectPath = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();




分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1136255
帖子:227251
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP