2016-06-28 1 views
0

動的レポートでいくつかのレポートを表示する必要があります。 NetBeansとTomcat 7を使用します。結局、すべてをOpenShiftクラウドにアップロードする必要があります。サーブレットに位置ブラウザにDynamicReportsを表示せずに、cliendドライブにダウンロードする方法は?

Connection conn=null; 
    try { 
    Class.forName(DBConnStrings.driver); 
    conn = DriverManager.getConnection(DBConnStrings.url + DBConnStrings.dbName+DBConnStrings.sslState, DBConnStrings.userName, DBConnStrings.password); 
    } catch (Exception e) { 
     e.printStackTrace(); 

    } 
    JasperReportBuilder report = DynamicReports.report(); 
    report 
      .columns(
        Columns.column("Tank Id", "id", DataTypes.integerType()), 
        Columns.column("Tank Name", "name", DataTypes.stringType()), 
        Columns.column("Label", "label", DataTypes.stringType()), 
        Columns.column("Description", "descrshort", DataTypes.stringType())); 
    report.setDataSource("SELECT id, name, label, descrshort FROM "+ DBConnStrings.dbName +".tbltankslist", conn); 

    try { 
      //show the report 
    //report.show(); 

      //export the report to a pdf file 
    report.toPdf(new FileOutputStream("c:/report.pdf")); 
} catch (DRException e) { 
    e.printStackTrace(); 
} catch (FileNotFoundException e) { 
    e.printStackTrace(); 
} 

このコード:私は、簡単なレポート(コードスニペット)を作成するDynamicReportsを使用しました。できます。最初はJasperViewerを、HDDにはreport.pdfを取得します。しかし、私はそれを望んでいません。最初はJasperViewerを見たくないのですが、2番目はクライアントのHDDにファイルをダウンロードしたくありません。 Webブラウザ内でのみレポートを表示する方法は?

Here is the question Jasper Reports.これは、ジャスパーレポート+ iReportについてのもので、DynamicReportsの情報をどのように使用するのかわかりません。最初は2番目に「クライアントドライブへのPDFダウンロード」アプローチがありますが、ブラウザ内に表示する必要があります。

答えて

1

あなたのファイルで、jasperPDFがダウンロードする代わりに新しいタブで開くように、ジャスパー呼び出しページにリダイレクトする次のコードを使用してください。あなたはjasperReport

<form method="POST" action="JasperInvocation.jsp" target="_blank"> 
0

を起動する

JasperInvocation.jsp =>ファイルには、次のコードを見つけてください、私は、ダイナミックレポート(ジャスパーAPI)、私にとってその作業に実装されている: -

@RequestMapping(value="/pdfDownload", method = RequestMethod.GET) 
public void getPdfDownload(HttpServletResponse response) { 
ByteArrayOutputStream buffer = new ByteArrayOutputStream(); 

report().columns().setDataSource().show() 
.toPdf(buffer); 

byte[] bytes = buffer.toByteArray(); 
InputStream inputStream = new ByteArrayInputStream (bytes); 
IOUtils.copy(inputStream, response.getOutputStream()); 
response.setHeader("Content-Disposition", "attachment; filename=Accepted1.pdf"); 
response.flushBuffer(); 

} 
関連する問題