response.addHeader("Content-Disposition", "attachment; filename=" +response.encodeURL(downloadfile));
attachment表明这是一个附件,浏览器不会寻找合适的应用程序打开文件,而是显示另存为对话框,如果这个值设成inline,则无论怎样浏览器都会自动尝试用已知关联的程序打开文件。
本文介绍如何通过设置HTTP响应头来实现文件的下载功能。重点解释了Content-Disposition响应头的使用方法,包括attachment与inline的区别,attachment使浏览器显示另存为对话框而inline则尝试用已知程序打开。
response.addHeader("Content-Disposition", "attachment; filename=" +response.encodeURL(downloadfile));
1578
2798

被折叠的 条评论
为什么被折叠?