web开发过程的上传下载,使用Tomcat6下载的文件名容易出现乱码。示例如下:
public static void export(HttpServletResponse response,Workbook wb,String fileName)throws Exception{
response.setHeader("Content-Disposition", "attachment;filename="+new String(fileName.getBytes("utf-8"),"iso8859-1"));
response.setContentType("application/ynd.ms-excel;charset=UTF-8");
OutputStream out=response.getOutputStream();
wb.write(out);
out.flush();
out.close();
这样在Tomcat7中下载的文件名是正常,但是Tomcat6依然是乱码,这里就需要将Tomcat6中的server.xml中的这两段稍微配置一下:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />
1
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8" />
如此就ok!如果还不行,就看看你的web.xml配置文件是否定义全局编码!
即 listings属性要设为true