1

フォームを送信しないボタンから Struts2 アクションを呼び出す方法を知る必要があります。ボタンをクリックすると、SSRS サーバー (SQL Server Reporting Services) への Web サービス呼び出しを行う Struts2 アクションが呼び出されます。サーバーは、Response に入れたストリームにレポートを送信します。次に、PDF ファイルをダウンロードするためのポップアップが表示されます。JSF では簡単です。commandButton は「action」属性を提供します。これと同等のものが欲しい:

<h:commandButton id="editButton" value="Edit" action="#{myBean.edit}" />

public class MyBean { public String edit() call web service, put the stream on the response return "OK"}}

Struts2 ではどうですか? アヤクサ?JQuery? 道場?私は Struts2 と Ajax は初めてで、多くの JSF を行っています。

ありがとうございました

4

2 に答える 2

3

フォームを送信しないと、AJAX.

ただし、PDF をダウンロードする必要があるだけなので、ストリーム結果を返すアクションに対して GET 呼び出しを実行するだけです(現在のページは変更されません)。

Read more here

を指定contentDisposition: attachmentすると、ファイルをダウンロードする場所 (またはファイルを開くために使用するアプリケーション) をユーザーに尋ねますがcontentDisposition: inline、ブラウザ内でファイルを開き、ページを変更します (それはあなたが望むものではありません)。

次に、URLでアクションを指定し、アンカータグを使用します

<s:url action="downloadAction.action" var="url">
    <s:param name="param1">value1</s:param>
</s:url>
<s:a href="%{url}" >download</s:a>

および Struts.xml で

<result name="success" type="stream">
   <param name="contentType">application/pdf</param>
   <param name="contentDisposition">attachment;filename="yourPDF.pdf"</param>
</result>

InputStreamアクションでは、(ゲッターを介して)呼び出された を提供する必要がありますinputStream

編集

コメントで尋ねたように、ボタンから実行したい場合:

<input  type = "button" 
       value = "download" 
     onclick = "javascript:location.href='downloadAction.action';"
/>
于 2013-09-25T08:33:29.293 に答える
0

Dojo では、iframe を作成し、レポート サービスへの ajax 呼び出しを行って PDF ファイル名を取得し、この PDF ファイルを ifrmae でダウンロードできます。

    var reportCP = new dijit.layout.ContentPane({
        content: dojo.create("iframe")
    });   

    new dijit.Button({
        label: "Report",
        onClick: function(){

            dojo.request.post(yourServiceUrl, {
                data : yourData,
                handleAs: "json"
            }).then( 
                function(response){
                    reportCP.content.src=response.fileName;   
                },
                function(error){
                    alert(error);
                }
            );
        }
    });  

または、window.open を使用して、pdf ストリームを新しいウィンドウに直接ダウンロードできます。

new dijit.Button({
    label: "Report",
    onClick: function(){
        window.open(yourReportServiceUrl,"","height=600, width=1000, scrollbars=1");
    }
});  
于 2013-09-24T18:09:14.100 に答える