一次性上傳多個檔案到伺服器端(一)

來源:互聯網
上載者:User

標籤:ret   eth   str   target   system   bsp   資料   color   attr   

頁面代碼:

<form name="form1" action="uploadFileJunior.html" method="post" ENCTYPE="multipart/form-data">    <input id="File1" name="fileupload" accept="file/*.*" multiple="multiple" type="file" value="" />    <input id="" type="submit" value="上傳" /></form>

上面實現多選的關鍵是multiple="multiple"一句。

 

幕後處理代碼:

    @RequestMapping("/uploadFileJunior")    public String uploadFileJunior(@RequestParam("fileupload") MultipartFile[] files,HttpServletRequest request,HttpServletResponse response){        try {                    int count=files.length;                        for(int i=0;i<count;i++){                MultipartFile file=files[i];                                InputStream is=file.getInputStream();                String fileName=file.getOriginalFilename();                System.out.println("File"+(i+1)+":"+fileName);                String newFilepath=fileService.upload2Server(is,fileName);                logger.info(i+":"+file.getOriginalFilename()+" "+" newFilepath="+newFilepath);                            }                        return "/pages/sample/index.jsp";        } catch (Exception e) {            e.printStackTrace();            logger.error(e);                        request.setAttribute("error", e.getClass());            request.setAttribute("reason", e.getMessage());            StackTraceElement[] arr=e.getStackTrace();            request.setAttribute("stackTraceElements", arr);                        return "pages/error/index.jsp";        }    }

注意好上面兩個fileupload的映射關係,後台這邊對應的變數數組是files,之後針對files進行處理就行了。

參考資料:

http://www.cnblogs.com/jingch/p/5036686.html

一次性上傳多個檔案到伺服器端(一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.