获取tomcat下webapp路径


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");

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM