0

我想在新的弹出窗口中显示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 流?
谢谢

4

0 回答 0