request.getRealPath()建议不使用,替换方法

request.getRealPath("");

这个方法已经不推荐使用了,替换方法为:

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

得到站点的绝对根路径,
如

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

得到项目的绝对根路径如下:

F:\devtools\apache-tomcat-7.0.42\webapps\malaoshi

而下面代码

request.getSession().getServletContext().getRealPath(“/temp”);

得到项目的绝对路径如下:

F:\devtools\apache-tomcat-7.0.42\webapps\malaoshi\temp