web开发过程的上传下载,使用Tomcat6下载的文件名容易出现乱码。示例如下:
1
2
3
4
5
6
7
|
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中的这两段稍微配置一下:
1
2
3
|
<
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配置文件是否定义全局编码!
本文转自 小夜的传说 51CTO博客,原文链接:http://blog.51cto.com/1936625305/1422484,如需转载请自行联系原作者