web(获取路径的方法)

 String path = this.getServletContext().getRealPath("/");
 String path2 = this.getClass().getClassLoader().getResource("/").getPath();
 String path3 = Thread.currentThread().getContextClassLoader().getResource("/").getPath();

输出结果如下:

path:E:\apache-tomcat-8.5.23-windows-x64\apache-tomcat-8.5.23\webapps\
path2:/E:/apache-tomcat-8.5.23-windows-x64/apache-tomcat-8.5.23/webapps/WEB-INF/classes/
path3:/E:/apache-tomcat-8.5.23-windows-x64/apache-tomcat-8.5.23/webapps/WEB-INF/classes/

posted @ 2017-11-29 21:35  beibidewomen  阅读(158)  评论(0编辑  收藏  举报