简体   繁体   English

直接在 Internet Explorer 中打开下载时出现文件名问题

[英]Issue with file name when directly opening download in Internet Explorer

We have a Java web application which generates reports and serves them directly as a binary response.我们有一个 Java web 应用程序,它生成报告并将它们直接作为二进制响应提供。 Until recently we were only generating PDF files (which are opened by the browser directly) this way, but recently we added the ability to generate the report as an XLS file as well.直到最近,我们才以这种方式生成 PDF 文件(由浏览器直接打开),但最近我们还添加了将报告生成为 XLS 文件的功能。 This seems to be creating issues in Internet Explorer when selecting "open" in the "what do you want to do" popup box.当在“你想做什么”弹出框中选择“打开”时,这似乎在 Internet Explorer 中产生了问题。

The URL that serves the report is of the form "http://localhost:8080/ias/ReportsClientInterface?req=fetch&jobid=2352837_1609341332985".为报告提供服务的 URL 的格式为“http://localhost:8080/ias/ReportsClientInterface?req=fetch&jobid=2352837_1609341332985”。 The MIME type we are setting is "application/vnd.ms-excel" and the Content-Disposition header is "filename=[name].xls" where [name] can vary based on the title of the report.我们设置的 MIME 类型是“application/vnd.ms-excel”,Content-Disposition header 是“filename=[name].xls”,其中 [name] 可以根据报告的标题而有所不同。 In Internet Explorer (11 running on Windows 10) the browser shows a "what do you want to do with [filename]?"在 Internet Explorer(在 Windows 10 上运行的 11)中,浏览器显示“你想用 [filename] 做什么?” popup .弹出 The [filename] on the popup correctly shows the file name specified by the Content-Disposition header.弹出窗口中的 [filename] 正确显示了 Content-Disposition header 指定的文件名。 If "save" is selected, the name chosen for the file is matching that header as well.如果选择“保存”,则为文件选择的名称也与 header 匹配。 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. 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. Worse, if we leave Excel open and generate a second report, Excel will refuse to open it because the second report also attempts to open with the name "ReportsClientInterface".更糟糕的是,如果我们让 Excel 打开并生成第二个报告,Excel 将拒绝打开它,因为第二个报告也尝试使用名称“ReportsClientInterface”打开。

Is there a way to force IE/Excel to honor the file name specified in the headers so this issue does not occur?有没有办法强制 IE/Excel 遵守标题中指定的文件名,这样就不会出现这个问题?

Thanks in advance.提前致谢。

Is there a way to force IE/Excel to honor the file name specified in the headers so this issue does not occur?有没有办法强制 IE/Excel 遵守标题中指定的文件名,这样就不会出现这个问题?

Rephrasing your question: "Is there a way to remotely fix this IE11 bug"?改写你的问题:“有没有办法远程修复这个 IE11 错误”?

The answer is, obvious but disappointingly: Of course, no, there is not.答案很明显但令人失望:当然,不,没有。

The usual fix is to mess with your server's routing system.通常的解决方法是弄乱服务器的路由系统。 You don't want the URL to be http://localhost:8080/ias/ReportsClientInterface?req=fetch&jobid=2352837_1609341332985 , you want it to be http://localhost:8080/ias/report/descriptiveNameOfReport/[name].xls?jobid=2352837_1609341332985 You don't want the URL to be http://localhost:8080/ias/ReportsClientInterface?req=fetch&jobid=2352837_1609341332985 , you want it to be http://localhost:8080/ias/report/descriptiveNameOfReport/[name].xls?jobid=2352837_1609341332985

Note that as a more general note, having ReportsClientInterface in your URL is extremely ugly and indicative that in general you've messed up on the routing part of writing web services.请注意,作为更一般的说明,在ReportsClientInterface中包含 ReportsClientInterface 非常难看,这表明您通常在编写 web 服务的路由部分时搞砸了。 URLs are important.网址很重要。 Pay more attention to them, and do not accept any routing system that results in such a mess (routing = the process that runs to tie a URL, such as /ias/ReportsClientInterface , to some handler - the java code that you wrote that is to respond to this. That's calling 'routing').更加注意它们,并且不要接受任何导致这种混乱的路由系统(路由=运行以将 URL (例如/ias/ReportsClientInterface )绑定到某些处理程序的进程 - 您编写的 java 代码是对此作出回应。这就是所谓的“路由”)。

I'm assuming that you are using an automated routing system, ie that you have, perhaps, a class named ReportsClientInterface and the routing system in place uses this to automatically load classes.我假设您正在使用自动路由系统,即您可能有一个名为ReportsClientInterface的 class 并且现有的路由系统使用它来自动加载类。 Or that you have some system that will produce eg XML that links this URL to your class.或者你有一些系统会产生例如 XML ,它将这个 URL 链接到你的 class。

Either way, look at the web framework you have and figure out how to take control of the routing, and then take a moment to inventory every service and page you expose, and think of a nice URL scheme for all of that.无论哪种方式,查看您拥有的 web 框架并弄清楚如何控制路由,然后花点时间清点您公开的每个服务和页面,并为所有这些考虑一个不错的 URL 方案。 Then implement this.然后实现这个。

Every webframework routes differently, so without knowing which one you use I can't go in further detail about how to do that job.每个网络框架的路由都不同,所以在不知道你使用哪一个的情况下,我无法 go 更详细地了解如何完成这项工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM