struts文件下载时默认文件名出现乱码,该怎么解决?

lee821129 2006-05-17 02:13:44
下载功能能实现,但是默认文件名是中文时,出现下载窗口时文件名乱码。
下面是我写的代码,请大家帮我看一下应该怎么改
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws IOException {

FileService fileService = FileService.getInstance();
String fileID = request.getParameter("fileID");
String filePath = fileService.getFilePath(fileID);
String fileName = filePath.substring(filePath.lastIndexOf("/")+1); System.out.println(fileName);
response.setContentType("application/octet-stream;charset=ISO-8859-1");
response.setHeader("Content-Disposition","attachment;filename=\"" + fileName + "\"");
ServletOutputStream out = response.getOutputStream();
FileInputStream in = new FileInputStream(filePath);
byte[] b = new byte[8196];
int i = 0;
while ((i = in.read(b)) > 0) {
out.write(b, 0, i);
}
out.close();
in.close();
return null;
}

...全文
127 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
gyb84021 2006-05-25
  • 打赏
  • 举报
回复
你是怎末解决得?
能告诉我吗?
我快让乱码整疯啦。
我的邮箱:guoyb@sisans.cn
flyxxxxx 2006-05-18
  • 打赏
  • 举报
回复
用URLEncode类的方法encode对fileName进行编码
lee821129 2006-05-18
  • 打赏
  • 举报
回复
改成GB2312还是了乱码呀
harston 2006-05-17
  • 打赏
  • 举报
回复
你把ISO-8859-1设为gbk2312试一下

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧