1

I have a problem in uploading files using struts2. I have multiple file tags like

<s:file name="fileUpload_5534" multiple="multiple"/>

<s:file name="fileUpload_5585" multiple="multiple"/>

<s:file name="fileUpload_5595" multiple="multiple"/>

These file tags are created dynamically and again can have multiple files uploads as I have specified multiple="multiple". Can anyone suggest the solution for this kind of uploads.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
Naveen Sangwan
  • 861
  • 1
  • 10
  • 10
  • 2
    Please consider looking at your question after you post it; you would have noticed your JSP fragment was invisible. You should have a map of files using normal S2 collection field naming syntax. – Dave Newton Oct 01 '13 at 12:37
  • Multiple File Upload Using Struts 2 :http://geekonjava.blogspot.com/2015/07/multiple-file-upload-using-struts-2.html – Tell Me How Jul 22 '15 at 12:28
  • @GeekOnJava or http://stackoverflow.com/a/17212916/1654265 ;) BTW good article – Andrea Ligios Sep 11 '15 at 10:04

1 Answers1

1

You can upload multiple files from a single <s:file> element with multiple="multiple" like described here.

You can also upload multiple files from many <s:file> elements (that allow a single file for each one) in the same way, handling the names of the <s:file>s to point to a list on the Action.

Do you really want to upload a Lists of Lists of Files ?

If yes, I suggest you to model an object, like MyFileListObject, containing the lists of data needed:

class MyFileListObject {
    private List<File> files;
    private List<String> filesContentType;
    private List<String> filesFileName;    

    /* getters and setters */
}

and then expose a List<MyFileListObject> through the Action.

Alternatively, you can granulate it more, defining a new object, like MyFileObject,

class MyFileObject {
    private File files;
    private String filesContentType;
    private String filesFileName;    

    /* getters and setters */
}

,listed in MyFileListObject:

class MyFileListObject {
    private List<MyFileObject> files;

    /* getter and setter */
}

and then expose a List<MyFileListObject> through the Action.

But it seems overkill to me... which kind of page should let many <input type="file"/> upload many files each one in a single post ?

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243