File Upload, download

Source: Internet
Author: User

File download is relatively simple, response set header tells the browser this is a file download and then Getoutputstream write to the designated place to go.

Such as:

Resp.setheader ("Content-disposition", "Attachment;filename=" +new String ("Test". GetBytes ("GBK"), "iso8859-1") + ". jpg" );

InputStream in = This.getclass (). getClassLoader (). getResourceAsStream ("1.jpg");

OutputStream out = Resp.getoutputstream ();

byte[] bytes = new byte[8192];
int len = 0;
while ((Len=in.read (bytes))!=-1) {
Out.write (bytes, 0, Len);
}
Out.flush ();
In.close ();
Out.close ();

File upload no trouble adding a file form field to a JSP the Enctype= "Multipart/form-data" method must be a post

Need to import two packages under apache.org in Commons Commons-fileupload-1.3.2.jar Commons-io-2.5.jar

Determine if the request is a file upload

Create a temporary warehouse for the parser to give the parser to the file upload object if it is created

Parsing requests

Determine if the normal form field is normal if it is not file upload processing

See File Upload code for details

File Upload, download

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.