/*** 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