multiple file upload in JSP struts
My client wants a feature (like i开发者_如何学JAVAn advanced Gmail version) where user can hold CTRL key and select multiple files to upload in one go. Is it really possible ? Please let me know your precious feedback/suggestions on this.
Thanks in advance.
Yes, S2 can handle multiple files. I don't know about the UI considerations. Although not an answer the the same question this will show someone else working with the file upload interceptor and the issue of multiple files at one time is brought up: Limit Struts2 file upload max size without uploading the whole file
Gmail is using Flash for this. If Flash is disabled, it gracefully degrades to a normal HTML <input type="file">
field which allows selection of only a single file at once.
There are several free Flash based libraries which allows to select multiple files in a single browse, the popular ones being SwfUpload and Uploadify. It's trivial to handle this in a JSP/Servlet backend with help of Commons FileUpload. I can only not tell in detail how to combine this with Struts since I don't use it.
Yes and it is integrated native in Struts 2. Read the doc. You can easily use this feature in your web form, just keep in mind that:
form
must be defined with this part:enctype="multipart/form-data" method='post'
fields are submitted by
name
. So:in the
jsp
page, define your<input type="file">
with aname=
, likename="fileInput"
, and in your action class, define them like the doc:File fileInput;
String fileInputContentType;
String fileInputFileName;
Or, as Array/List:
File[] fileInput; //this array will contain all the input file fields with name="fileInput", so name all fields with the same name.
String[] fileInputContentType;
String[] fileInputFileName;
And getters/setters. And Struts 2 do the rest perfectly.
精彩评论