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

转载自:https://blog.csdn.net/kouwoo/article/details/40507627

request.getSession().getServletContext() 获取的是Servlet容器对象,相当于tomcat容器了。
getRealPath("/") 获取实际路径,"/"指代项目根目录,所以代码返回的是项目在容器中的实际发布运行的根路径
 
   
在工程的WebContent下新建一个upload的目录

// 文件保存路径
String filePath = realPath + "upload/"+ file.getOriginalFilename();

转载于:https://www.cnblogs.com/aiyowei/p/11309133.html

你可能感兴趣的:(request.getSession().getServletContext().getRealPath("/");)