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 want to know how could I create a loop or something in the jsp struts2 form such that when a user uploads a file it adds its name to a list and he/she could upload another file and be added to the list and so on.
相关问题
- Java/Struts2: How to get action name from current
- Upload file to Google Cloud Storage using AngularJ
- #{facesContext} EL expression not resolved at runt
- codeigniter $this->upload->do_upload() = false
- NPE in StrutsTestCase after enabling Tiles
I implemented this by using two struts2 plugin which are, Struts2 JQuery Plugin and Struts2 Scope Plugin
The answer is as following:
include those dependencies in your maven POM file:
and we create a class to prepare the form as follows:
and a class for the add to list and to handle ajax call as follows:
and finally the jsp should be something like:
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
here
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