获取tomcat下webapp路径

时间:2020-05-08 16:19:14   收藏:0   阅读:70

1

 ServletRequestAttributes att=(ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
  HttpServletRequest request = att.getRequest();
  request.getSession().getServletContext().getRealPath("/") ;

 

2

String resoucePath=当前类.class.getResource("/").getPath();
String webappsDir=(new File(resoucePath,"../../")).getCanonicalPath();

 

3 在propertie文件里写死路径

去读取

Properties properties = new Properties();
InputStream in =当前类.class.getClassLoader().getResourceAsStream("demo.properties");
properties.load(in);
String webapps = properties.getProperty("path");

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!