在自己写的download这个servlet或者下载的jsp页面中,添加head信息时,加入这些代码
response
.
setContentType
(
“application/octet-stream”
);
byte
[]
b
=
fileName
.
getBytes
(
“GBK”
);
fileName = new String ( b , “8859_1″ );
response . setHeader ( “Content-Disposition” , “attachment;filename=” + fileName );
fileName = new String ( b , “8859_1″ );
response . setHeader ( “Content-Disposition” , “attachment;filename=” + fileName );
有时候这样仍然不能保证下载到的文件是正确的,需要设置上传页面的代码格式,设置成utf-8测试成功,gbk没有试过,gb2312测试失败。charset=utf-8是最好的选择。设置完成后如果用的不是utf-8的编码格式会出现页面的乱码,这时候将这个文件另存(推荐使用EditPlus),选择编码格式为utf-8就可以了。