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