1

我们正在为我们的客户生成 PDF 文档并使用 Servlet 为他们提供服务。以下代码适用于 Firefox、Chrome 和 Opera,但不适用于任何版本的 IE。弹出窗口只闪烁 IE 但没有任何反应。但是,我们可以通过从 IE 的地址栏直接请求 servlet 来显示文件下载对话框。我们尝试了几种 ContentType(应用程序/下载、应用程序/x-download 等)

客户端代码:

String URL = "/files/pdf?pdfId=" + getPdfId();
Window.open(URL, "_blank", "");

Servlet 将 pdf 作为字节 [] 提供服务:

byte[] bytes = getFileAsByteArray();
BufferedInputStream in = new BufferedInputStream(new ByteArrayInputStream(bytes));
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
response.setHeader("Content-Disposition", "attachment; filename=document.pdf");
response.setContentType("application/octet-stream");
response.setContentLength(bytes.length);
byte[] buffer = new byte[8192];
for (int length = 0; (length = in.read(buffer)) > 0;) {
    out.write(buffer, 0, length);
}
out.flush();
out.close();

对此有什么想法吗?

4

4 回答 4

2

试试这个:

Content-Disposition: inline

代替:

Content-Disposition: attachment;filename=document.pdf

试试这个,然后告诉一些事情 发现如果我使用 inline 那么我不应该使用 filename=document.pdf,这在 IE 中不起作用。(其他浏览器无视)

你可以在这里阅读:http: //indiwiz.com/2009/03/11/forcing-http-download/

于 2011-07-14T20:45:00.227 回答
0

这可能是因为pdf插件问题。 链接到 adobe 网站以获取更多详细信息

于 2011-07-13T08:36:27.247 回答
0

如果您无法解决问题 - 尝试更改问题中的某些内容!尝试发送压缩的 pdf 文件或其他内容。它应该可以帮助您找到问题的根源。如果一切都适用于 zip 文件,则无需发送 pdf 文件

于 2011-07-13T16:51:17.980 回答
0

尝试 :

Window.open(GWT.getHostPageBaseURL()+URL,"","");

这可能有效!我正在使用 :

com.google.gwt.user.client.Window.open(GWT.getHostPageBaseURL()+URL, "", "");   

它工作得很好

于 2012-02-29T14:23:16.723 回答