JAVA下载中文名异常问题

阅读更多
String agent = request.getHeader("User-Agent");
boolean isMSIE = (StringTools.hasText(agent) && agent.toUpperCase()
.indexOf("MSIE") != -1);
// ie10以上的user agent中不再带有msie字符,
boolean isIE10 = StringTools.hasText(agent)
&& agent.indexOf("Trident") != -1 && agent.indexOf("rv") != -1;
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control", "no-cache");
response.setContentType("application/octet-stream;charset=ISO8859-1");
String s = "中文文件名.doc";
if (isMSIE || isIE10) {
response.setContentType("application/x-download");// 设置为下载application/x-download
response.addHeader("Content-Disposition", "attachment;filename="
+ URLEncoder.encode(s, "UTF-8"));

} else {
response.addHeader("Content-Disposition", "attachment;filename="
+ StringTools.getStringUTF2ISO(s));
}

你可能感兴趣的:(中文文件名乱码,java,ie)