about Java File download file name garbled problem solutionAs a programmer, we should all have encountered the problem of garbled! This article is self-addressed about the handling of Java file download file name garbled problem:String filename = "filename downloaded";String useragent = Request.getheader ("user-agent");
For IE or IE as the kernel browser:
if (Useragent.contains ("MSIE") | | Useragent.contains ("Trident")) {
filename = java.net.URLEncoder.encode (filename, "UTF-8");
} else {
Non-IE browser processing:
FileName = new String (filename.getbytes ("UTF-8"), "iso-8859-1");
}
Response.setheader ("Content-disposition", String.Format ("attachment; Filename=\ "%s\", "fileName");
Response.setcontenttype ("Application/vnd.ms-excel;charset=utf-8");
Response.setcharacterencoding ("UTF-8");
You can do it like this! By the way: each browser aboutRequest.getheader ("user-agent");Output content: chrome:mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/33.0.1750.154 safari/537.36
firefox:mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) gecko/20100101 firefox/32.0
ie8:mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; trident/4.0;. NET CLR 2.0.50727; SLCC2;. NET CLR 3.5.30729;. NET CLR 3.0.30729; infopath.3;. net4.0c;. NET4.0E)
ie9:mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; trident/5.0)
ie10:mozilla/5.0 (Windows NT 6.1; WOW64; trident/7.0; rv:10.0) Like Gecko
ie11:mozilla/5.0 (Windows NT 6.1; WOW64; trident/7.0; rv:11.0) Like Gecko
360 Speed Mode: mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/38.0.2125.122 safari/537.36
360 IE9 Mode: mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; trident/5.0)
About Java File download file name garbled problem solution