springMVC 中 webuploader同时上传多个文件

it2022-05-07  36

springMVC 中 webuploader同时上传多个文件

1 导入包 webuploader-0.1.5

2 配置

3 jsp中代码

<th width="20%">上传:</th>     <td>              <div id="upload">             <div id="filePicker">文件上传</div>         </div>         <script type="text/javascript">             var uploader = WebUploader.create(                 {                     swf:"${ctx}/static/webuploader-0.1.5/Uploader.swf",                     server:"${ctx}/express/checkResult/uploadSeal",                     pick:"#filePicker",                     auto:true,                     accept: {                         title: 'Images',                         extensions: 'gif,jpg,jpeg,bmp,png',                         mimeTypes: 'image/*'                     }                 }                    );         </script>         <textarea  id="uploadCover" name="uploadCover"  style="width:200px; display:none"  text=""></textarea> 

3 写controller

public static String COM_REPORT_PATH = "D:";  @RequestMapping("uploadSeal")     public void upload(@RequestParam(value = "file", required = false) MultipartFile file,HttpServletResponse response, HttpServletRequest request, ModelMap model) {           System.out.println("upload image 开始");           String path =COM_REPORT_PATH+"/upload/";           String fileName = file.getOriginalFilename();           System.out.println(path);           File baseFile = new File(path);   File targetFile = new File(baseFile, fileName);      long size=0;   if(!baseFile.exists()){      baseFile.mkdirs();           }                 //保存           try {               file.transferTo(targetFile);              size  = file.getSize();         } catch (Exception e) {               e.printStackTrace();           }           System.out.println(path+fileName);         model.addAttribute("fileUrl", path+fileName);        PrintWriter out;   try {    request.setCharacterEncoding("utf-8");    response.setCharacterEncoding("utf-8");    out = response.getWriter();  //    out.println("文件上传成功. 已保存为: " + path + "." + fileName//      + "   文件大小: " + size + "字节<p />");    out.println("<input type='hidden' name='imgaddress' value='"+ path + "." + fileName+"'>");   } catch (IOException e) {    e.printStackTrace();   }        } 

转载于:https://www.cnblogs.com/Elsie/p/7084405.html

相关资源:垃圾分类数据集及代码

最新回复(0)