开发者

multiple file upload in JSP struts

开发者 https://www.devze.com 2023-02-15 16:35 出处:网络
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

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 a name=, like name="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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号