Multiple file uploads in struts 2

前端 未结 1 1084
挽巷
挽巷 2021-01-25 14:49

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



        
相关标签:
1条回答
  • 2021-01-25 15:20

    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 ?

    0 讨论(0)
提交回复
热议问题