应用程序的期望行为是,在提供默认文件名的同时提示用户选择下载位置,这在IE和FF中运行良好,但Chrome总是自动将其强制下载到下载目录。我知道Chrome在“设置-高级-每次下载时询问保存位置”选项中有此功能。该选项的缺点是它适用于所有页面,而我们测试过其他项目需要遵循内联行为,因此这些情况会直接冲突。我搜索了一下,但没有找到任何明确说明Chrome是否支持此功能,但我认为奇怪的是,这种长期存在并与多个RFC相关联的行为未被Chrome遵循,而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);
}
}
有人有任何想法吗?这不可能吗?解决方法?如果您需要更多细节,请让我知道。