spring mvc 下载文件 IE浏览器文件名是乱码

来源:互联网 发布:windos系统优化设置 编辑:程序博客网 时间:2024/03/29 10:15

http://blog.csdn.net/heyanfeng22/article/details/49453405


页面下载文件时,内容都是中文,只有文件名是乱码,在谷歌等浏览器下是可以的,查了下资料是浏览器兼容性问题

写一个转换

/**     *      * @Title: processFileName     *      * @Description: ie,chrom,firfox下处理文件名显示乱码     */     public static String processFileName(HttpServletRequest request, String fileNames) {         String codedfilename = null;         try {             String agent = request.getHeader("USER-AGENT");             if (null != agent && -1 != agent.indexOf("MSIE") || null != agent                     && -1 != agent.indexOf("Trident")) {// ie                   String name = java.net.URLEncoder.encode(fileNames, "UTF8");                   codedfilename = name;             } else if (null != agent && -1 != agent.indexOf("Mozilla")) {// 火狐,chrome等                     codedfilename = new String(fileNames.getBytes("UTF-8"), "iso-8859-1");             }         } catch (Exception e) {             e.printStackTrace();         }         return codedfilename;     }  


0 0
原创粉丝点击