获取javaweb的路径

java类获取classpath路径

获取WEB-INF/class路径。

this.getClass().getResource("/").getPath()

根据user.dir获取的路径在java项目中获取项目路径,而在web项目中获取的是tomcat/bin下面。

System.getProperty("user.dir")

Servlet中获取项目路径

获取项目路径

request.getSession().getServletContext().getRealPath("")

JSP中获取项目路径

jsp中获取项目路径

new java.io.File(application.getRealPath(request.getRequestURI())).getParent();

参考:

https://blog.csdn.net/qq_34445857/article/details/79223526

原文地址:https://www.cnblogs.com/aeolian/p/12452459.html