- 在servlet里面使用:String path = getServletContext().getRealPath("/");
- 取得应用classes的全路径:this.getClass().getClassLoader().getResource("/").getPath();
- 利用jsp内置对象:String path = pageContext.getServletContext().getRealPath("/");
String realPath = path+"/WEB-INF/classes/abc.properties"; - 今天同事想到的办法:使用filter。这样就更灵活的得到web应用的上下文,从而简单的取得路径。
java类获取当前应用的绝对路径
最新推荐文章于 2025-01-10 21:42:35 发布