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> 
  • 相关阅读:
    向 DataGridView 的行集合中添加行
    添加form窗口最大化最小化事件
    转义字符表
    键盘输入变简单了
    数字9X9的表格
    统计你输入的任意字符
    一个九九表
    用冒泡法排序
    学生会
    任意排序几个数
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/4972372.html
Copyright © 2011-2022 走看看