java导出文件IE/Google文件名乱码兼容

 

导出文件名乱码解决方案:

1 String agent = request.getHeader("User-Agent");
2 boolean isMSIE = (agent != null && agent.indexOf("MSIE") != -1);
3 if( isMSIE ){
4   finalFileName = java.net.URLEncoder.encode(exportFileName,"UTF8");
5 }else{
6   finalFileName = new String(exportFileName.getBytes("UTF-8"), "ISO-8859-1");
7 }
8             
9 response.setHeader("Content-Disposition", "attachment; filename=\"" + finalFileName + "\"");//设置为浏览器弹出下载提示框,而非直接在浏览器中打开

 

posted @ 2017-03-16 16:15  习惯沉淀  阅读(744)  评论(0编辑  收藏  举报