日期:2014-05-16  浏览次数:20302 次

JSP中文附件名问题
帖一段代码,这段代码用于处理IE与Firefox下的中文编码问题:
String expName = "";
if(request.getHeader("user-agent").indexOf("Firefox") > 0){
xpName = new String("智能服务机当日挂号分析.xls".getBytes("UTF-8"), "ISO-8859-1");
}else{
expName = URLEncoder.encode("智能服务机当日挂号分析.xls", "UTF-8");
}

response.setHeader("Content-Disposition", new StringBuilder("attachment;filename=\"").append(expName).append("\"").toString());
response.setContentType("application/msexcel");
workbook.write();
workbook.close();


这段代码可以解决在firefox与IE下附件中文乱码问题。
如果还是有乱码的话,在tomcat/server.xml中URI编码加上:
 <Connector port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" URIEncoding="UTF-8"/>