无request时
WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
ServletContext servletContext = webApplicationContext.getServletContext();
//文件的路径
String strFilePath = servletContext.getRealPath("/").replace("rest", "web") + CommonConstant
.FILE_TEMP_FOLDER;
有request时
//文件的名称
String absoluteStrFilePath = request.getServletContext().getRealPath("/").replace("rest", "web") +
CommonConstant.FILE_TEMP_FOLDER;
relativeFileUrl = request.getContextPath().replace("rest", "web") +
"/" + CommonConstant.FILE_TEMP_FOLDER + "/" + fileName;
网友评论