Struts2 Document upload Error

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.