Struts2 multi-File Upload

Source: Internet
Author: User

Introduction: I found some plug-ins on the Internet when I was uploading multiple files at a time, so that I could upload multiple files at a time, but there was a problem when I put them in Struts2, therefore, the Struts2 file is used for uploading. Although you need to select a file multiple times, it can also be uploaded at one time. Let's take a look at my implementation methods and use them to inspire others...

Let's take a look at the Code required by jsp:

Window. onload = function () {// Add button for file upload $ ("# addUpload "). click (function () {var fileDiv = $ (". fileDiv "). clone (); fileDiv. removeClass (); // remove class = "fileDiv" if you do not do this, multiple classes = "fileDiv" will be displayed. In this way, multiple classes will be cloned again, added $ ("# fileTr") in the proportional sequence "). append (fileDiv); fileDiv. show () ;}) // delete a file $ (". delUpload "). live ("click", function () {$ (this ). closest ("DIV "). remove () ;}< tr> <td align = "left" width = 5%> Import result: </td> <td align = "left" width = 5%> <span id = "addUpload" style = "border: gray 1px solid; padding: 5px 15px; background-color: # BABABA; color: # 000fff; "> added </span> </td> <td id =" fileTr "align =" left "width = 15% nowrap> <div class =" fileDiv "style =" font- size: 12px; padding: 5px; display: none; "> path: <input type =" file "name =" resultFile "style =" background-color: # fff; border: solid 1px #77abc4; color: #000000; width: 270px; "/> <span class =" delUpload "style =" border: gray 1px solid; padding: 5px 15px; background-color: # BABABA; color: # 000fff; "> Delete </span> </div> </td> </tr>

As follows:

Click Delete:

Background code:

Private List <File> resultFile; // corresponds to private List <String> resultFileFileName with the name = "resultFile" in jsp; // you can obtain the list of uploaded files cyclically, then perform the operation for (int I = 0; I <resultFile. size (); I ++) {String fileReName = uploadFile (resultFile. get (I), resultFileFileName. get (I ));}

The code is rough and will focus on the meeting. If you have good recommendations, I hope you will not give me any further. Thank you !!!





Zookeeper

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.