您的位置:首页 > 产品设计 > UI/UE

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

2016-01-20 11:08 411 查看
无论是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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: