在HTTP请求中创建的PDF将无法在Internet Explorer中打开 [英] PDF created on HTTP request won't open in Internet Explorer

查看:147
本文介绍了在HTTP请求中创建的PDF将无法在Internet Explorer中打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有servlet根据请求中的一些参数动态生成PDF到响应。当我尝试在IE中打开/下载此文件时,我收到以下消息:

I've got servlet that makes a PDF on the fly to the response, based on some parameters on the request. When I try to open/download this file in IE I get the following message:

无法从[site]下载[filename]。
无法打开这个网站。请求的网站要么无法使用,要么找不到。请稍后再试。

"Unable to download [filename] from [site]. Unable to open this Internet site. The requested site is either unavaliable or cannot be found. Please try again later."

这是我设置的回复:

response.setHeader("Content-Disposition", "attachment;filename=" + title + ".pdf");

response.setContentType("application/pdf");

其他浏览器一切正常。

更新:

我尝试过内联而非附件。这将打开一个新窗口,而不是打开/保存对话框(我希望有对话框),错误消息消失了,但新窗口在IE中只是空的。仍在使用其他浏览器。

I've tried inline instead of attachment. This will open a new window instead of a open/save dialog (I would prefer to have the dialog), the error message is gone, but the new window is just empty in IE. Still working with other browsers.

我在文件名周围尝试过简单,双重和没有引号,它不包含任何未转义的字符。 Double和没有引号没有区别,但单个文件会附加到文件名,我当然不想要。

I've tried simple, double and no quotes around the filename, which does not contain any unescaped characters. Double and no quotes makes no difference, but single ones are appended to the filename, which I of course don't want.

文件名不包含未转义的字符。

The filename contains no unescaped characters.

我已经检查了这个的测试页面,其中说明为所有浏览器传递附件,带文件名,无引号。这是从一开始就使用的。

I've checked out the tests on this page, which says that attachement, with filename, no quotes, is passed for all browsers. This is what was used from the start.

添加Content-Lenght标题没有区别。

Adding Content-Lenght header makes no difference.

Flying Saucer用来制作PDF,顺便说一下。

Flying Saucer is used to make the PDF, by the way.

推荐答案

这已经有一段时间了,但我想我应该更新一下,作为一个找到了解决方案。

This been a while, but thought I should update this, as a solution was found.

正在使用的CMS添加了一些我最初没有考虑的标题:

The CMS in use was adding some headers wich I did not take into consideration at first:


  • Cache-Control:private

  • Pragma:no-cache

如果没有缓存,似乎是IE的下载问题。这些标题在CMS的升级中被更改,这解决了问题。

Seems to be a download problem with IE, if there is no caching. Those headers were changed in an upgrade of the CMS, and that solved the problem.

示例:


  • 缓存控制:public,max-age = 31536000

  • 日期:星期四,2012年12月6日14:14:14 GMT

  • 到期日:2013年12月6日星期五14:14:14 GMT

这篇关于在HTTP请求中创建的PDF将无法在Internet Explorer中打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆