During file download, ie and Firefox process different file name encoding! Content-Disposition

Source: Internet
Author: User

Response. setheader ("content-disposition", "attachment; filename=123_file .txt ")


The first-mover file name is stored in the data warehouse on the 8th. The file name must be a Chinese file 123.txt and then downloaded as follows:
Response. setcontenttype ("application/octet-stream; charset = UTF-8 ");
Filename = java.net. urlencoder. encode (filename, "UTF-8 ");
Response. setheader ("content-disposition", "attachment; filename =" + filename );
Percent % 0a

Then I tried another solution.
Response. setcontenttype ("application/octet-stream; charset = UTF-8 ");
Filename = new string (filename. getbytes ("UTF-8"), "iso-8859-1 ");
Response. setheader ("content-disposition", "attachment; filename =" + filename );
When downloaded from the internet, the file names are garbled and the firefoxfile displays the latest Chinese file 123.txt.

I want Internet Explorer to display the latest Chinese file 123.txt. I wonder if you have encountered a similar problem. What is the solution?
It may be a solution to determine the browser type for different processing, but this is a solution that I personally think is mandatory.


String agent = request. getheader ("User-Agent"); <br/> If (null! = Agent &-1! = Agent. indexof </P> <p> ("MSIE") <br/> {<br/> string codedfilename = urlencoder. encode (cfrfilename, "utf8"); <br/> response. setcontenttype (</P> <p> "application/X-download"); <br/> response. setheader ("content-disposition", "attachment; filename =" + codedfilename); </P> <p >}< br/> else if (null! = Agent &-1! = Agent. indexof ("Mozilla") </P> <p >{< br/> string codedfilename = mimeutility. encodetext (cfrfilename, "utf8", "B"); <br/> response. setcontenttype ("application/X-download" </P> <p>); <br/> response. setheader ("content-disposition", "attachment; filename =" + codedfilename ); <br/>}</P> <p> else <br/>{< br/> response. setcontenttype ("application/X-download"); <br/> response. setheader ("content-disposition", </P> <p> "attachment; filename =" + cfrfilename); <br/>}< br/>



Source: http://www.javaeye.com/topic/50414

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.