Struts2 File Upload

后端 未结 2 444
挽巷
挽巷 2020-12-20 02:34

I want to upload multiple files in one form and that number of files is varying from user to another, ex. a user may upload 2 files and another user could upload 12 files. I

2条回答
  •  难免孤独
    2020-12-20 03:07

    You can use build in Struts2 multiple file uploading feature.In your Jsp file you have to define something like

    
        
        
        
        
    
    

    which will send these files to Your action class and you have the option of Collecting the file content as a list

    public class MultipleFileUploadUsingListAction extends ActionSupport {
    
        private List uploads = new ArrayList();
        private List uploadFileNames = new ArrayList();
        private List uploadContentTypes = new ArrayList();
        // There getter and setter methods
    
    }
    

    here

    [File Name] : File - the actual File
    [File Name]ContentType : String - the content type of the file
    [File Name]FileName : String - the actual name of the file uploaded (not the HTML name)
    

    For detail refer to the multiple file upload page of Struts2

    Multiple File Upload

    Showing user an option to add more file on the JSP page is matter of how to want to display that.All you need to take care when you show him file-upload box name should be same so that Struts2 param interceptor can set them as a list in your Action class

提交回复
热议问题