1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
try { //下面这句必须加,不然报错 MultipartResolver resolver = new CommonsMultipartResolver(hsq.getSession().getServletContext()); MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) hsq; //获取一起跟文件传过来的其他参数值 String id = multipartRequest.getParameter("id"); //获取上传上来的文件 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); for (Map.Entry<String, MultipartFile> entry : fileMap.entrySet()) { MultipartFile file = entry.getValue(); String fileName = file.getOriginalFilename(); System.out.println(fileName); String path = "C:\\Users\\user\\Desktop\\" + fileName; file.transferTo(new File(path)); } } catch (Exception e) { e.printStackTrace(); } |
from:https://www.cnblogs.com/sanrenblog/p/15648871.html