先贴上上传文件的完整代码@RequestMapping("upload.do")
@ResponseBody
public ServerResponse upload(HttpSession session, @RequestParam(value = "upload_file",required = false) MultipartFile file, HttpServletRequest request){
User user = (User)session.getAttribute(Const.CURRENT_USER);
if(user == null){
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),"用户未登录,请登录管理员");
}
if(iUserService.checkAdminRole(user).isSuccess()){
String path = request.getSession().getServletContext().getRealPath("upload");
String targetFileName = iFileService.upload(file,path);
String url = PropertiesUtil.getProperty("ftp.server.http.prefix")+targetFileName;
Map fileMap = Maps.newHashMap();
fileMap.put("uri",targetFileName);
fileMap.put("url",url);
return ServerResponse.createBySuccess(fileMap);
}else{
return ServerResponse.createByErrorMessage("无权限操作");
}
}
我在开启断点调试时发现通过语句String path = request.getSession().getServletContext().getRealPath("upload");
获得的path的值是D:\apache-tomcat-7.0.81\webapps\ROOT\upload,为什么通过String targetFileName = iFileService.upload(file,path);
这句代码就能将文件传到C:\ftpfile\img文件夹里面呢?明明我FTP Server 指定的共享目录是上一级目录C:\ftpfile(如下图),是不是我理解的有问题?