Info:unable to find ' struts.multipart.saveDir ' property setting was presented today when writing a document upload. Defaulting to Javax.servlet.contex hint error, later found write data discovery is struts.xml less configuration
Modify the method to add <constant name= "Struts.multipart.saveDir" value= "/tmp" in Struts2.xml ></constant> OK. If you implement multiple uploads of a document, just add a few <input to the foreground JSP page type= "file" name= "file" >
's form. Add private static final String path= "d:\\file\\" to the background action class;//File storage path
Private list<file> file;//upload file array
Private list<string> filefilename;//file name, which is an array of file names
private string filecontenttype;//records the type of each uploaded file, String type
The file is the Name property in the input control (the name value is the name of the file) and the uploaded document can be stored in the folder by the following code:
if (upload!=null) {
Looping through files
for (int i=0;i<upload.size (); i++) {
Fetch to file stream
InputStream is=new FileInputStream (Upload.get (i));
Creating a file output stream
OutputStream os=new FileOutputStream (Path+uploadfilename.get (i));
Cache bytes
byte buffer[]=new byte[1024];
Cache byte Size
int count=0;
Write a file
while ((Count=is.read (buffer)) >0) {
Os.write (Buffer,0,count);
}
Close the stream
Os.close ();
Is.close ();
}
}
Struts2 Document upload Error