我想在新的弹出窗口中显示pdf流,但是当流为空时,我想在当前页面中编写错误消息(Edition.jsp)
在Edition.jsp页面中:
<s:form id="pdf" action="ExportPdf" theme="simple" target="pageEdition" >
...
<sj:menu name="typeEdition" cssClass="edition" list="listeEditions" />
</s:form>
在struts.xml中:
<action name="ExportPdf" class="ExportPdfAction">
<result name="success" type="stream">
<param name="inputName">inputStreamPdf</param>
<param name="contentType">application/pdf</param>
<param name="contentDisposition">filename="myFile.pdf"</param>
<param name="bufferSize">2048</param>
</result>
<result name="error">/WEB-INF/web/Edition.jsp</result>
</action>
javascript,当我点击菜单项目版本
时$('.edition').bind('click', function(even, data) {
window.open('', 'pageEdition', 'location=no, menubar=no, height=600, width=900' );
$('#pdf').submit();
});
当我返回错误时,我不想进入目标页面。
是的,我通过Ajax JQuery尝试,但现在,问题是显示pdf!
// click on the menu item edition
$('.edition').bind('click', function(event, data) {
$('#pdf').submit();
});
$('#pdf').submit(function(event) {
// stop form from submitting normally
event.preventDefault();
// post with parameters
var posting = $.post( $( this ).attr( 'action' ), $('#pdf').serialize());
// wait results
posting.done(function( data, event ) {
if (data.substring(0,4) != '%PDF') {
alert ("error");
} else {
// the format pdf is recognize, but not display (the stream is in the url, but not in the content)
window.open('data:application/pdf,'+ data, 'pageEdition', 'menubar=no, height=600, width=900' );
}
});
当我使用此解决方案时,流响应(数据参数)无法正确显示。流在URL中,但不在内容中。 我试着用:
window.document.write(data);
但它是html内容
如何在javascript中显示pdf流?
感谢