方法一:
String realPath=request.getSession().getServletContext()
.getRealPath("upload");
方法二:
WebApplicationContext webApplicationContext = ContextLoader .getCurrentWebApplicationContext(); ServletContext servletContext = webApplicationContext .getServletContext(); // 得到文件夹绝对路径 String realPath = servletContext.getRealPath("upload");