獲取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