【发布时间】:2021-04-07 02:31:50
【问题描述】:
我们有一个 Java Web 应用程序,它可以生成报告并将其作为二进制响应直接提供。直到最近,我们才以这种方式生成 PDF 文件(由浏览器直接打开),但最近我们还添加了将报告生成为 XLS 文件的功能。在“你想做什么”弹出框中选择“打开”时,这似乎会在 Internet Explorer 中产生问题。
提供报告的 URL 格式为“http://localhost:8080/ias/ReportsClientInterface?req=fetch&jobid=2352837_1609341332985”。我们设置的 MIME 类型是“application/vnd.ms-excel”,Content-Disposition 标头是“filename=[name].xls”,其中 [name] 可以根据报告的标题而有所不同。在 Internet Explorer(在 Windows 10 上运行的 11)中,浏览器显示“你想用 [文件名] 做什么?” popup。弹出窗口中的 [filename] 正确显示了 Content-Disposition 标头指定的文件名。如果选择“保存”,则为文件选择的名称也与该标题匹配。 However, when "open" is selected, Excel shows ReportsClientInterface (which is in the URL as shown above) as the name, instead of the expected report name.更糟糕的是,如果我们让 Excel 保持打开状态并生成第二个报告,Excel 将refuse 打开它,因为第二个报告也尝试使用名称“ReportsClientInterface”打开。
有没有办法强制 IE/Excel 遵守标题中指定的文件名,以免出现此问题?
提前致谢。
【问题讨论】:
标签: java excel internet-explorer mime content-disposition