firefox下载附件乱码问题

来源:互联网 发布:蒋方舟扒皮知乎 编辑:程序博客网 时间:2024/06/06 02:54

原文:https://www.oschina.net/question/3288681_2244885


String agent = request.getHeader("USER-AGENT");if(agent != null && agent.indexOf("Firefox") > -1){//火狐浏览器下载附件乱码    String enableFileName = "=?UTF-8?B?" + (new String(Base64.encodeBase64(po.getAttachmentName().getBytes("UTF-8")))) + "?=";    response.setContentType("application/force-download");    // 中文需要编码    response.addHeader("Content-Disposition",            "attachment;fileName="+enableFileName);}else if(agent != null && agent.indexOf("MSIE") > -1){//IE浏览器下载附件    String enableFileName = new String(po.getAttachmentName().getBytes("UTF-8"), "ISO-8859-1");    response.setContentType("application/force-download");    // 中文需要编码    response.addHeader("Content-Disposition",            "attachment;fileName="+enableFileName);}else {//其他浏览器下载附件    // 强制下载不打开    response.setContentType("application/force-download");    // 中文需要编码    response.addHeader("Content-Disposition",            "attachment;fileName=" + URLEncoder.encode(po.getAttachmentName(), "utf-8"));}

原创粉丝点击