标签:
@RequestMapping(value = "/upload") public String handleFormUpload(MultipartHttpServletRequest request){ String b = request.getParameter("a"); System.out.println(b+"aaaaaaaaaaaaaaaaaaa"); List<MultipartFile> file = request.getFiles("file"); String path = this.servletContext.getRealPath("/tmp/"); // 获取本地存储路径 System.out.println(path + "-----------------"); System.out.println(file.size()+"====================="); FileOutputStream fileOutputStream = null; for (int i = 0; i < file.size(); i++) { if (!file.get(i).isEmpty()) { String fileName = file.get(i).getOriginalFilename(); String a = fileName.split("\\.")[1]; File files = new File(path + new Date().getTime() +i+ "."+a); // 新建一个文件 try { fileOutputStream = new FileOutputStream(files); fileOutputStream.write(file.get(i).getBytes()); System.out.println(file.get(i).getOriginalFilename()+ "-----------------"); System.out.println(file.get(i).getContentType()+ "-----------------"); fileOutputStream.flush(); } catch (Exception e) { e.printStackTrace(); } if (fileOutputStream != null) { // 关闭流 try { fileOutputStream.close(); } catch (IOException ie) { ie.printStackTrace(); } } } } return "redirect:top"; }
<form method="post" enctype="multipart/form-data" action="<c:url value="fileUpLoad/upload.html"/>" > <input type="text" name="a"/> <input type="file" name="file" /> <input type="file" name="file" /> <input type="file" name="file" /> <input type="file" name="file" /> <input type="file" name="file" /> <input type="submit" /> </form>
标签:
原文地址:http://www.cnblogs.com/zhujiabin/p/4972372.html