and a single file upload configuration is the same, just accept the parameter in the action, accept the array, is no longer a single file.
One, the action implementation:
public class Mutablefilesupload extends Actionsupport {private static final long Serialversionuid = 1l;public file[] Uploa Dobjects;public string[] uploadobjectsfilename;public string[] uploadobjectscontenttype;public String moreInfo; Public String upload () {System.out.println (moreinfo);//1. Get Servletcontextservletcontext ServletContext = Servletactioncontext.getservletcontext ();//2. Call the Realpath method to get the real directory based on a virtual directory string Realpath = Servletcontext.getrealpath ("/files");//3. If the real directory does not exist, you need to create a file File = new file (Realpath); if (!file.exists ()) { File.mkdirs ();} 4. Save the File//cut: Cut the temporary file to the specified location and rename it. Note: The temp file does not have a for (int i = 0; i < uploadobjects.length; i++) {System.out.println ("one file name:" + uploadobjectsfilename[ I]); Uploadobjects[i].renameto (new file (file, uploadobjectsfilename[i]));} return SUCCESS;}}
Two, configure the action
<action name= "Mutable_uploads" class= "gy.upload.MutableFilesUpload" method= "Upload" > <!--Specify (limit) the type of upload file, Define the local interceptor, modify the default Interceptor's property "Fileupload.maximumsize": Limit the upload maximum file size. "Fileupload.allowedtypes": the type of file that is allowed to be uploaded. "Fileupload.allowedextensions": An extensible file type that allows files to be uploaded. --<interceptor-ref name= "Defaultstack" > <param name= "fileupload.maximumsize" >500000000</param > <param name= "fileupload.allowedtypes" >text/plain,application/vnd.ms-powerpoint</param> <param Name= "Fileupload.allowedextensions" >.txt,.ppt</param> </interceptor-ref> <result>/ Success.html</result> <!--An error automatically returns the input result, into the results view--<result name= "input" >/fail.html</result ></action>
Third, the implementation of the form
<body><form action= "Mutable_uploads" method= "post" enctype= "Multipart/form-data" > File:<br> < Input type= "file" Name= "uploadobjects" ><br><input type= "file" Name= "Uploadobjects" ><br> more Info:<input type= "text" name= "moreinfo" ><br><input type= "Submit" value= "Submit" ><br></form ></body>
Use of the Java Web struts2 framework-multiple file uploads based on forms