You can use build in Struts2 multiple file uploading feature.In your Jsp file you have to define something like
<s:form action="doMultipleUploadUsingList" method="POST" enctype="multipart/form-data">
<s:file label="File (1)" name="upload" />
<s:file label="File (2)" name="upload" />
<s:file label="FIle (3)" name="upload" />
<s:submit />
</s:form>
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<File> uploads = new ArrayList<File>();
private List<String> uploadFileNames = new ArrayList<String>();
private List<String> uploadContentTypes = new ArrayList<String>();
// 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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…