Java solves the problem of garbled file names and java garbled characters when downloading files from IE browsers.
/*** Differentiate ie from other browsers for garbled download files * @ param request * @ param fileName * @ return */public String getFileName (HttpServletRequest req, String fileName) {String userAgent = req. getHeader ("user-agent"); userAgent = null? "": UserAgent. toLowerCase (); String name = fileName; try {
// For IE or IE-based browsers: if (userAgent. contains ("msie") | userAgent. contains ("trident") {name = URLEncoder. encode (name, "UTF-8");} else {name = new String (name. getBytes (), "iso-8859-1");} catch (Exception e) {throw new SysException (ERRORConstants. COMMON_SYSTEM_ERROR, e);} return name ;}
In many examples on the internet, msie and like Gecko are used to distinguish between them. ie11 is used to remove msie;
The msie of like Gecko and ie11 was not removed and marked with a trident.
The conclusion is that like Gecko is not used for differentiation.
Public void exportExcel (HttpServletRequest req, HttpServletResponse response) {try {response. setContentType ("application/octet-stream"); String excelName = "file name"; response. addHeader ("Content-Disposition", "attachment; filename =" + getFileName (req, excelName) + ". xls "); OutputStream out = response. getOutputStream (); testService. export (out);} catch (Exception e ){//}}