Content-disposition中Attachment和inline的区别

时间:2024-01-09 19:13:08
1.Content-disposition中Attachment和inline的区别
java web中下载文件时,我们一般设置Content-Disposition告诉浏览器下载文件的名称,是否在浏览器中内嵌显示.
Content-disposition: inline; filename=foobar.pdf
表示浏览器内嵌显示一个文件 Content-disposition: attachment; filename=foobar.pdf
表示会下载文件,如火狐浏览器中 Content-disposition中Attachment和inline的区别

2.内嵌显示(可用于在线浏览pdf)示例:

response.setHeader("Content-disposition", "inline; filename="
+ new String(fm.getFileName().getBytes("gb2312"), "ISO8859-1")); 3.下载示例:
response.setHeader("Content-disposition", "attachment; filename="
+ new String(fm.getFileName().getBytes("gb2312"), "ISO8859-1"));