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