1-2.txt
来自「一次上传多个文件。 允许得到上传的文件的原文件名」· 文本 代码 · 共 35 行
TXT
35 行
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object cmd, BindException errors)
throws Exception {
FileUploadBean bean = (FileUploadBean) cmd;
byte[] bytes = bean.getFile();
//cast to multipart file so we can get additional information
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
CommonsMultipartFile file = (CommonsMultipartFile) multipartRequest.getFile("file");
String uploadDir = this.getUploadDir();
File dirPath = new File(uploadDir);
if (!dirPath.exists()) {
dirPath.mkdirs();
}
String sep = System.getProperty("file.separator");
if (log.isDebugEnabled()) {
log.debug("uploading to: " + uploadDir + sep +
file.getOriginalFilename());
}
File uploadedFile = new File(uploadDir + sep
+ file.getOriginalFilename());
FileCopyUtils.copy(bytes, uploadedFile);
System.out.println("********************************");
System.out.println(uploadedFile.getAbsolutePath());
System.out.println(bytes.length);
System.out.println("********************************");
return new ModelAndView(getSuccessView() + ".jsp");
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?