web(获取路径的方法)

it2024-08-02  56

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/

转载于:https://www.cnblogs.com/beibidewomen/p/7922853.html

最新回复(0)