[Java] 纯文本查看 复制代码
protected MultipartParsingResult parseRequest(HttpServletRequest request) throws MultipartException {
String encoding = this.determineEncoding(request);
FileUpload fileUpload = this.prepareFileUpload(encoding);
try {
List ex = ((ServletFileUpload)fileUpload).parseRequest(request);
return this.parseFileItems(ex, encoding);
} catch (SizeLimitExceededException var5) {
throw new MaxUploadSizeExceededException(fileUpload.getSizeMax(), var5);
} catch (FileUploadException var6) {
throw new MultipartException("Could not parse multipart servlet request", var6);
}
}
[Java] 纯文本查看 复制代码
if(!ServletFileUpload.isMultipartContent(request)){
//如果上传的数据不是表单原始的数据(经过编码),则直接返回。因为只有表单原始数据才会被接收
//http://stackoverflow.com/questions/4526273/what-does-enctype-multipart-form-data-mean
return;
}
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
dynamicsText = multipartRequest.getParameter("dynamicsText");//获取表单文本部分
MultipartFile multipartFile = multipartRequest.getFile("dynamicsFile");//获取表单
String savePath = request.getSession().getServletContext().getRealPath("/") + "user_space/"+userId;
File file = new File(savePath);
if (!file.exists() && !file.isDirectory()) {
file.mkdirs();//新建文件夹(多重)
}
dynamicsFile = multipartFile.getOriginalFilename();
multipartFile.transferTo(new File(savePath+"/"+dynamicsFile));