【发布时间】:2015-03-11 23:33:27
【问题描述】:
应用程序的期望行为是提示用户提供下载位置,同时提供默认文件名,该文件名在 IE 和 FF 中运行良好,但 Chrome 总是自动将其强制下载到下载目录。
我知道 chrome 在“设置”>“高级”>“下载前询问每个文件的保存位置”中有一个选项。这个选项的缺点是它适用于所有页面,而我测试过的其他项目是我们想要的遵循内联行为,因此这些案例彼此直接冲突。
我四处搜索,但找不到任何明确的说明它在 Chrome 中是可能的还是不可能的,但我觉得奇怪的是,一种已经存在了这么久并且附加了多个 RFC 的行为不受 Chrome 的遵守总是被宣传为符合标准。 这是根据 Chrome 开发工具在浏览器中接收标头的方式
HTTP/1.1 200 OK
Content-Type: application/vnd.ms-powerpoint
Content-Disposition: attachment; filename="presentation.ppt"
Content-Language: en-US
Transfer-Encoding: chunked
Date: Tue, 13 Jan 2015 19:18:27 GMT
Server: WebSphere Application Server/7.0
这是设置标头服务器端的代码
public void generatePowerPoint(HttpSession session, HttpServletResponse response){
String id = (String) session.getAttribute(ApplicationConstants.ID);
SlideShow ppt = reportService.generatePowerPoint(id);
try{
StringBuilder sb = new StringBuilder();
sb.append("presentation_").append(id).append(".ppt");
response.setContentType("application/vnd.ms-powerpoint");
response.setHeader("Content-Disposition", "attachment; filename=\"" + sb.toString()+ "\"");
OutputStream out = response.getOutputStream();
ppt.write(out);
out.flush();
out.close();
}
catch(IOException e) {
logger.error("The ppt could not be generated: ", e);
}
}
有人有意见吗?不可能吗?解决方法?如果您需要更多详细信息,请告诉我。
【问题讨论】:
标签: java google-chrome browser content-disposition