您的位置:首页 > 其它

web工程常用路径的获取方法

2016-12-08 17:34 323 查看
此文章是基于  搭建Jquery+SpringMVC+Spring+Hibernate+MySQL平台

一. 利用 Spring 取得web工程根路径

  1. web.xml 中添加如下:

<context-param>
<param-name>webAppRootKey</param-name>
<param-value>webapp.root</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.util.WebAppRootListener</listener-class>
</listener>


View Code
  

  2. Java中通过如下代码取得根路径:

private static String webrootPath = System.getProperty("webapp.root");


二. Java取得当前类的class路径

String classPath = this.getClass().getResource("").getPath();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: