zoukankan      html  css  js  c++  java
  • springMVC 中 webuploader同时上传多个文件

    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="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
    //      + " &nbsp;&nbsp;文件大小: " + size + "字节<p />");
        out.println("<input type='hidden' name='imgaddress' value='"+ path + "." + fileName+"'>");
       } catch (IOException e) {
        e.printStackTrace();
       }   
         } 

  • 相关阅读:
    【科普】.NET 泛型
    吐槽,青岛科技大学真他妈操蛋
    c# 数组和集合精讲
    c# System.Text.Json 精讲
    .NET 5的System.Text.Json的JsonDocument类讲解
    c#中Array,ArrayList 与List<T>的区别、共性与转换
    代码是怎么运行的?
    .NET6使用DOCFX根据注释自动生成开发文档
    spring通过注解注册bean的方式+spring生命周期
    莫比乌斯反演
  • 原文地址:https://www.cnblogs.com/Elsie/p/7084405.html
Copyright © 2011-2022 走看看