Jsp、Servlet、Spring controller中获取绝对路径

获取当前web应用的绝对路径

JSP中,可以通过 application.getRealPath("/"); 获取.

 

在servlet中,可以通过 getServletContext().getRealPath("/");

 

在Spring的controller中,由于其不是Servlet, 所以只能使用传入的参数request来完成.

由于request.getRealPath("/") 已经不再推荐使用.所以这儿使用:

 

request.getSession().getServletContext().getRealPath("/");获取绝对路径。

你可能感兴趣的:(spring,jsp,Web,servlet)