Overview
It is convenient to group same type of Form Inputs with an ArrayList (or other types of List). For checkbox this is easily done in Struts Framework, but how about "File" or other types of input?
Reference
Uploading Multiple Files using Struts FormFile
Code Snippet
I copy the code from the reference link above and do some change on it in order to get the uploaded files in the order shown in the User's Form.
In JSP File
<form name="fileupload" enctype="multipart/form-data" method="post" action="/photos/fileuploadresult">
<tr>
<td>Photo 1</td>
<td><input type="file" name="uploads[0]" /></td>
</tr>
<tr>
<td>Photo 2</td>
<td><input type="file" name="uploads[1]" /></td>
</tr>
<tr>
<td><input type='submit' name="submit" value="Submit"></td>
<tr>
</form>
In struts-config.xml
<action path="/photos/fileuploadresult" type="com.uploads.actions.FileUploadAction" name="PhotoUpload" scope="request" >
<forward name="success" path="/photos/fileuploadresult.jsp" />
</action>
<form-bean name="PhotoUpload" type="com.uploads.forms.FileUploadForm">
</form-bean>
In FileUploadForm.java
public class FileUploadForm extends ActionForm { |
沒有留言:
發佈留言