Download site image code and parse garbled _jsp programming

Source: Internet
Author: User
Copy Code code as follows:

Get web site objects
ServletContext context = This.getservletcontext ();
Get web site Resources
String Path = Context.getrealpath ("/imgs/person. jpg");
File File = new file (path);
System.out.println (file);
Set the response header to inform the browser how data is handled
Response.setheader ("Content-disposition",
"Attachment;filename=" +
Urlencoder.encode (File.getname (), "Utf-8")); Handle file name garbled specify picture format for download
Specify a byte input stream object
FileInputStream in = new FileInputStream (file);
Get byte output stream object
Servletoutputstream out = Response.getoutputstream ();
Write while reading
byte [] b = new byte[1024];
int len = 0;
while (len = In.read (b))!=-1) {
Out.write (b, 0, Len);
}
Releasing resources
In.close ();

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.