About Java File download file name garbled problem solution

Source: Internet
Author: User

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

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.