zoukankan      html  css  js  c++  java
  • SpringMVC批量上传

    @RequestMapping(value = "/upload")
     public String handleFormUpload(MultipartHttpServletRequest request){  
      String b = request.getParameter("a");
      System.out.println(b+"aaaaaaaaaaaaaaaaaaa");
      List<MultipartFile> file = request.getFiles("file");
      String path = this.servletContext.getRealPath("/tmp/"); // 获取本地存储路径
      System.out.println(path + "-----------------");
      System.out.println(file.size()+"=====================");
      FileOutputStream fileOutputStream = null;
      for (int i = 0; i < file.size(); i++) {
       if (!file.get(i).isEmpty()) {
        String fileName =  file.get(i).getOriginalFilename();
        String a = fileName.split("\.")[1];
        File files = new File(path + new Date().getTime() +i+ "."+a); // 新建一个文件
        try {
         fileOutputStream = new FileOutputStream(files);
         fileOutputStream.write(file.get(i).getBytes());
         System.out.println(file.get(i).getOriginalFilename()+ "-----------------");
         System.out.println(file.get(i).getContentType()+ "-----------------");
         fileOutputStream.flush();
        } catch (Exception e) {
         e.printStackTrace();
        }
        if (fileOutputStream != null) { // 关闭流
         try {
          fileOutputStream.close();
         } catch (IOException ie) {
          ie.printStackTrace();
         }
        }
       }
      }
       return "redirect:top";
     }
    <form method="post"&nbsp; enctype="multipart/form-data" action="<c:url value="fileUpLoad/upload.html"/>" >
    &nbsp; <input&nbsp; type="text" name="a"/>
    &nbsp;&nbsp; <input type="file" name="file" />
    &nbsp;&nbsp; <input type="file" name="file" />
    &nbsp;&nbsp; <input type="file" name="file" />
    &nbsp;&nbsp; <input type="file" name="file" />
    &nbsp;&nbsp; <input type="file" name="file" />
    &nbsp;&nbsp; <input type="submit" />
    &nbsp; </form> 
  • 相关阅读:
    Python的__init__.py用法
    Python中文
    使用apache进行域名绑定
    Storm入门之第二章
    Storm入门之第一章
    【RabbitMQ+Python入门经典】兔子和兔子窝 笔记
    RabbitMQ之Topics(多规则路由)
    RabbitMQ之比较好的资料
    RabbitMQ之路由
    RabbitMQ之发布订阅
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/4972372.html
Copyright © 2011-2022 走看看