admin管理员组文章数量:1530938
chrome IE 浏览器下载正常,火狐下载时文件名中有中文就会乱码
原来 Firefox浏览器自己会对URL进行一次转码。
解决办法:正对不同浏览器区别对待处理
public static String getExplorerType(HttpServletRequest request){
String agent = request.getHeader("USER-AGENT");
if(agent != null && agent.toLowerCase().indexOf("firefox") > 0){
return "firefox";
}else if(agent != null && agent.toLowerCase().indexOf("msie") > 0){
return "ie";
}else if(agent != null && agent.toLowerCase().indexOf("chrome") > 0){
return "chrome";
}else if(agent != null && agent.toLowerCase().indexOf("opera") > 0){
return "opera";
}else if(agent != null && agent.toLowerCase().indexOf("safari") > 0){
return "safari";
}
return "others";
}
public ExportExcel write(HttpServletRequest request,HttpServletResponse response, String fileName) throws IOException{
response.reset();
response.setContentType("application/octet-stream; charset=utf-8");
if("firefox".equals(ExplorerUtil.getExplorerType(request))){
//火狐浏览器自己会对URL进行一次URL转码所以区别处理
response.setHeader("Content-Disposition", "attachment; filename="+ new String(fileName.getBytes("GB2312"),"ISO-8859-1"));
}else{
response.setHeader("Content-Disposition", "attachment; filename="+ Encodes.urlEncode(fileName));
}
write(response.getOutputStream());
return this;
}
版权声明:本文标题:Firefox 火狐 浏览器下载文件文件名中文乱码解决 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1726115174a1056017.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论