public boolean upload(HttpServletRequest request,HttpServletResponse response) throws Exception {
//CommonsMultipartFile MultipartFile // for (int i = 0; i < file.length; i++) { // // if(!file[i].isEmpty()){ // File newFile = new File(imagePath + "//" + new Date().getTime() // + file[i].getOriginalFilename()); // file[i].transferTo(newFile); // // // } // // } // // return true; // @RequestParam MultipartFile[] myfiles // // // // 创建一个通用的多部分解析器 CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver( request.getSession().getServletContext()); //判断 request 是否有文件上传,即多部分请求 if(multipartResolver.isMultipart(request)){ //转换成多部分request MultipartHttpServletRequest multiRequest = CommonUtil.resolveMultipart(request, response); //取得request中的所有文件名 Iterator<String> iter = multiRequest.getFileNames(); Iterator<String> fileName = multiRequest.getFileNames(); while(fileName.hasNext()){ String fString=fileName.next(); System.out.println(fString); } System.out.println(); while(iter.hasNext()){ //取得上传文件 List<MultipartFile> files = multiRequest.getFiles(iter.next()); for (int i = 0; i < files.size(); i++) { MultipartFile file=files.get(i); if(!file.isEmpty()){ File newFile = new File(imagePath + "//" + new Date().getTime() + file.getOriginalFilename());file.transferTo(newFile);
} } } } return true;}