解决IE、FF下载时中文名问题

String fileName = request.getAttribute("filename");//如果Tomcat的URIEncoding没有设置为utf-8,则此时fileName为ISO8859_1编码
fileName = new String(fileName.getBytes("ISO8859_1"),"utf-8");

String agent = request.getHeader("USER-AGENT");
if(null != agent && -1 != agent.indexOf("MSIE")){
	fileName = URLEncoder.encode(fileName, "utf-8");
}else if(null != agent && -1 != agent.indexOf("Mozilla")){
	fileName = new String(fileName.getBytes("utf-8"), "ISO8859_1");
}

response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");// 设置下载保存的文件名


你可能感兴趣的:(tomcat,String,IE,null,mozilla)