Upload Download---Download

Source: Internet
Author: User

Download1the. Download is the response to the client byte data!  It turns out that we're all responding to HTML character data! Turn a file into a byte array, use Response.getoutputstream () to each browser!!! 2. Requirements for download*two heads a stream! > Content-type: What MIME type is the file you pass to the client, for example: image/Pjpeg*Call ServletContext's GetMimeType () method with the file name to get the MIME type! > content-disposition: Its default value is inline, which means it opens in a browser window! Attachment;filename=XXX* in Filename=followed by the file name that appears in the Download box! >Stream: The file data to download! *your own new one input stream can! ---------------------------Download the details1when the Chinese name appears in the download box, garbled characters appear. *firefox:base64 encoding. *Most other browsers: URL encoding. General scenario: FileName=NewString (Filename.getbytes ("GBK"), "Iso-8859-1");  Public StaticString filenameencoding (string filename, httpservletrequest request)throwsIOException {String Agent= Request.getheader ("user-agent");//Get Browser        if(Agent.contains ("Firefox") {Base64encoder Base64encoder=NewBase64encoder (); FileName= "=?utf-8?"                    B? " + Base64encoder.encode (filename.getbytes ("Utf-8"))                    + "?="; } Else if(Agent.contains ("MSIE") ) {filename= Urlencoder.encode (filename, "Utf-8"); } Else{filename= Urlencoder.encode (filename, "Utf-8"); }        returnfilename; }------------------------------------------------------

Upload Download---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.