Java to solve the Internet Explorer download file, file name garbled problem

Source: Internet
Author: User

 /*** to distinguish between IE and other browser download file garbled problem *@paramRequest *@paramFileName *@return     */     Publicstring GetFileName (httpservletrequest req,string fileName) {string useragent= Req.getheader ("User-agent"); UserAgent= UserAgent = =NULL?"": Useragent.tolowercase (); String name=FileName; Try {
For IE or IE as the kernel browser:if(Useragent.contains ("MSIE") | | Useragent.contains ("Trident") ) {Name= Urlencoder.encode (Name, "UTF-8")); }Else{Name=NewString (Name.getbytes (), "Iso-8859-1"); } } Catch(Exception e) {Throw Newsysexception (Errorconstants.common_system_error, E); } returnname; }

Online Many examples are used msie and like Gecko to make a distinction, said Ie11 removed MSIE;

Personally test Google browser also with like Gecko,ie11 msie not removed, and with Trident tag

The conclusion is not to use like Gecko to make a distinction, and finally

 Public void Exportexcel (httpservletrequest req,httpservletresponse response) {        try{              Response.setcontenttype ("Application/octet-stream");               = "file name";              Response.AddHeader ("Content-disposition", "Attachment;filename=" +getfilename (req,excelname) + ". xls");              = response.getoutputstream ();              Testservice.export (out);          } Catch (Exception e) {//          }          

Java resolves Internet Explorer download file, file name garbled problem

Related Article

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.