Under src New, struts.properties file, filename is fixed, used to change some of the default configuration.
You can find the default configuration file under Struts2 jar package, and generally do not modify that file.
Struts.multipart.savedir=d:/upload
struts.multipart.maxsize=9000000
Struts2 uploading files is not as simple as the direct upload we imagined.
You need to upload it to the temporary file first, and then move to the specified directory.
The bulk upload is the case, and now the form is set to the same name.
<form action= "Upload.action" method= "post" enctype= "Multipart/form-data" >
<input type= "file" name= Files "><br>
<input type=" file "name=" files "><br>
<input type=" file "name=" Files " ><br>
<input type= "Submit" value= "Upload" >
</form>
And then handle it in action.
private list<file> files; Name to be consistent.
private list<string> filesfilename;//The latter two naming formats are fixed
private list<string> filescontenttype;
All that's left is to traverse it and conquer it.
public string Execute () throws Exception {
//placed under the files file
string path = Servletactioncontext.getrequest (). Getrealpath ("/files");
int n = files.size ();
for (int i=0; i<n; i++) {
InputStream is = new FileInputStream (Files.get (i));
OutputStream OS = new FileOutputStream (New File (Path,filesfilename.get (i)));
byte[] buffer = new BYTE[1024*10];
int length = 0;
while (-1!= (length = is.read (buffer)) {
os.write (buffer, 0, length);
}
Is.close ();
Os.close ();
}
Return SUCCESS
}
}