Resolve Response.AddHeader ("content-disposition", "attachment; Filename= "+ file. Name) Chinese display garbled

Source: Internet
Author: User
Tags knowledge base
If file. Name is Chinese and is garbled. Solution is
Method 1:
Response.setheader ("Content-disposition", "attachment; Filename= "+ java.net.URLEncoder.encode (fileName," UTF-8 "));
Download the program has the above sentence, generally in the IE6 download prompt box will correctly display the name of the file, whether it is Simplified Chinese, or Japanese. But the text as long as more than 17 words, can not download.
A. Through the original way, that is, first with Urlencoder encoding, when the Chinese text more than 17, IE6 can not download files. This is the bug of IE, see Microsoft Knowledge Base article KB816868. The reason may be that when IE handles the Response header, the header length is limited to about 150 bytes. and a encoding into UTF-8 is 9 bytes, then 17 words is 153 bytes, so will be an error. And the suffix is not right.
Method 2:
Response.setheader ("Content-disposition", "attachment;filename=" + New String (Filename.getbytes ("gb2312"), " Iso8859-1 "));
In the case of ensuring that the attachment file name is in simplified text, then this method is indeed the most effective, do not allow customers to upgrade the IE. If Taiwan compatriots use, change gb2312 to Big5 on the line. But now the system is usually joined by the internationalization of support, universal use of UTF-8. If there is a simplified Chinese text in the file name, there is also traditional English, and Japanese. Then the garbled is produced. In addition, on the Firefox (v1.0-en) download is garbled.

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.