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

 

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

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

 

上一篇:《asp.net mvc3 高级编程》第一章


下一篇:linux安装perl模块