【发布时间】:2009-04-17 18:39:31
【问题描述】:
我有一个 servlet,它将 pdf 文件作为 ByteArrayOutputStream 写入 servlet 的输出流。 如果我打开 servlet URL,浏览器会打开文件。 但是,如果 servlet 发生错误,浏览器会打开一个带有错误消息的空 pdf。 通过 ServletResponse 发送错误浏览器会打开默认错误页面。
我想在不重定向到错误页面或打开无效 pdf 文件的情况下发送错误消息。
我试过了:
new Ajax.Request('/pdfservlet', {
onSuccess: function(response) {
docWindow = window.open('','title');
docWindow.document.open('application/pdf');
docWindow.document.write(response);
docWindow.document.close();
},
onFailure: function(response) {
alert(response);
}
});
但是,onSuccess 打开一个页面 [对象对象]
如何使用 JavaScript 打开 PDF 文件?
【问题讨论】:
标签: javascript ajax pdf prototypejs