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();
       }   
         } 

  • 相关阅读:
    java编程思想概括(第二章)一切都是对象
    java编程思想概括(第六章)复用类
    .net程序在无.net环境下运行
    一个让人哭笑不得的触发器
    iReaper for android
    博易博客删除垃圾评论
    解决博易2.0版分页问题
    允许更新此预编译站点的作用
    java包的命名规则技巧
    简易拨号器iCall
  • 原文地址:https://www.cnblogs.com/Elsie/p/7084405.html
Copyright © 2011-2022 走看看