簡體   English   中英

使用jasperReport顯示報告后,Glassfish關閉

[英]Glassfish shutdown after displaying a report using jasperReport

我正在使用JSF開發一個應用程序,並且正在使用Glassfish服務器,該應用程序使用jasperReport生成報告,該應用程序運行良好並生成報告(pdf格式),這些報告存儲在磁盤上,問題是我使用時

  JasperViewer.viewReport(jasperPrint);

向用戶顯示報告,然后嘗試繼續使用我的應用程序,該應用程序不起作用,我應該重新運行該應用程序!

在控制台上,錯誤是:

Completed shutdown of Log manager service

我的代碼:

public void fillReport() throws ParseException, groovyjarjarcommonscli.ParseException {

    try {
        // - Connexion à la base

        Driver monDriver = new com.mysql.jdbc.Driver();
        DriverManager.registerDriver(monDriver);
        connection = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/Mybase", "root", "root");

        // - Chargement et compilation du rapport

        JasperDesign jasperDesign = JRXmlLoader.load("C:/Documents and Settings/report2.jrxml");
        JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
        Map parameterMap = new HashMap();

        parameterMap.put("DateFrom", formatingDateTime(date1));
        parameterMap.put("DateTo", formatingDateTime(date2));
        parameterMap.put("SQL", Createquery());
        // // - Execution du rapport
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameterMap, connection);
        JasperViewer.viewReport(jasperPrint);
        JasperExportManager.exportReportToPdfFile(jasperPrint,"C:/Documents and Settings/report2.pdf");




    } catch (JRException e) {

        e.printStackTrace();
    } catch (SQLException e) {

        e.printStackTrace();
    } finally {
        try {
            connection.close();
        }

我應該怎么做才能解決這個問題?

ps:我在堆棧流上發現了同樣的問題,但是沒有解決方案(我不想刪除JasperViewer.viewReport(jasperPrint),因為它對於我來說顯示報告很簡單)

Jasper報告生成PDF,然后Glassfish崩潰/關閉

我不想刪除JasperViewer.viewReport(jasperPrint),因為對我來說顯示報告很簡單

JasperViewer.viewReport()將在本地(即在運行Glassfish的計算機上JasperViewer.viewReport()顯示報告,並且對遠程用戶沒有用。 您需要做的是將PDF文件從磁盤發送給用戶,以便他們下載並打開它。

還可以查看: http : //jasperreportjsf.sourceforge.net/web/index.html,用於JasperReports的JSF集成。

如果行

JasperViewer.viewReport(jasperPrint);

導致此問題,您可以嘗試將其圍繞在try-catch-Throwable中:

try {
    JasperViewer.viewReport(jasperPrint);
} catch (Throwable t) {
    t.printStackTrace();
}

這里重要的是捕獲Throwable ,它是Error / Exception層次結構的頂級類,因此它捕獲了所有內容 特別是,它捕獲了未經檢查的錯誤-我懷疑您可能會遇到其中之一。

但是,如果該方法中的代碼調用System.exit() ,則可以使用此不錯的解決方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM