您的位置:首页 > 其它

处理下载时候显示文件名中有中文的问题

2015-12-11 14:48 92 查看
此文章就是淡出的处理中文名,下载代码网上多的是,此处不写啦。

public String getStr(HttpServletRequest request, String realFileName)

throws Exception {

String browName = null;

String clientInfo = request.getHeader("User-agent");

System.out.println(clientInfo);

if (clientInfo != null && clientInfo.indexOf("MSIE") > 0) {//

// IE采用URLEncoder方式处理

if (clientInfo.indexOf("MSIE 6") > 0

|| clientInfo.indexOf("MSIE 5") > 0) {// IE6,用GBK,此处实现由局限性

browName = new String(realFileName.getBytes("GBK"),

"ISO-8859-1");

} else {// ie7+用URLEncoder方式

browName = java.net.URLEncoder.encode(realFileName, "UTF-8");

}

} else {//其他浏览器

browName = new String(realFileName.getBytes("GBK"), "ISO-8859-1");

}

return browName;

}

String fileName = getStr(req, attachmentView.getOldName());

response.setCharacterEncoding("GB2312");

response.setContentType("application/x-msdownload");

response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: