Arry's cnBlog

Barcelona win

博客园 首页 新随笔 联系 订阅 管理

文件下载该注意的问题:


(1)对于某些文件(jpg,txt),会在页面中显示而不是下载的问题;通过添加content-disposition头来处理上面问题。当设置了content-disposition头后,浏览器就会弹出下载框。而且还可以通过content-disposition头来指定下载文件的名称!

response.addHeader("content-disposition", "attachment;filename=" + filename);


(2)下载文件名是中文的问题;只需要通过URL来编码中文即可!

获取参数时:

filename = new String(filename.getBytes("ISO-8859-1"), "UTF-8");

返回到浏览器时:

// 所有浏览器都会使用本地编码,即中文操作系统使用GBK

// 浏览器收到这个文件名后,会使用iso-8859-1来解码

filename = new String(filename.getBytes("GBK"), "ISO-8859-1")。

posted on 2016-12-16 09:49  Arry  阅读(150)  评论(0编辑  收藏  举报