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/