spring mvc中获取项目绝对路径
2017-02-28 15:32
281 查看
spring mvc中获取项目绝对路径的方式
1.HttpServletRequest
public String getPath(HttpServletRequest request, Model model) throws Exception{String basePath = request.getServletContext().getRealPath("/");
return "";
}
2.使用了spring
(1).配置web.xml如下:
<context-param><param-name>webAppRootKey</param-name>
<param-value>test.webapp</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.WebAppRootListener</listener-class>
</listener>
(2).程序中通过如下代码即可获取
String basePath = System.getProperty("test.webapp");注:
(1).param-value节点可以任意取值,确保同一tomcat下值不同即可;
(2).basePath = basePath.replaceAll("\\\\", "/");//地址统一为'/'分隔,便于在UNIX服务器上使用。
相关文章推荐
- J2EE web项目,绝对路径和相对路径如何设置与获取
- j2ee项目中在java类中获取,项目的绝对路径 spring框架的
- C# Class获取项目的绝对路径
- javaWeb项目下获取当前类的绝对路径
- 如何获取android项目下某个文件的绝对路径
- windows linux 下,获取java项目绝对路径的方法
- 获取Web项目发布的绝对路径
- JavaScript中获取当前项目的绝对路径
- 获取发布后项目在服务器的绝对路径
- JavaScript中获取当前项目的绝对路径
- 如何获取android项目下某个文件的绝对路径
- J2EE项目相对路径、绝对路径获取
- J2EE项目相对路径、绝对路径获取
- WEB项目,获取详细路径,工程项目名称,在绝对(详细)地址基础获取工程项目名称
- 获取项目各种路径 类:classpath目录的绝对路径,request取得路径
- windows linux 下,获取java项目绝对路径的方法
- android获取项目下的一张图片的绝对路径问题以及解决方法
- android获取项目下的一张图片的绝对路径问题以及解决方法
- (转)J2EE WEB项目中获取相对路径与绝对路径的方法
- JSP之项目路径问题(${pageContext.request.contextPath},<%=request.getContextPath()%>以及绝对路径获取)