开发者

Glassfish shutdown after displaying a report using jasperReport

I am developping an application using JSF and I am using the Glassfish server ,this application generate report using jasperReport,the application work fine and generate reports(pdf format) ,those reports are stored on my disk,the problem is when I use

  JasperViewer.viewReport(jasperPrint);

to display the report to the user and then try to continue using my application it didn't work ,I should re-run the application!

On the console the error is:

Completed shutdown of Log manager service

My code:

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();

        paramete开发者_Python百科rMap.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();
        }

What should I do to resolve this problem?

Ps:I have found the same problem on stackflow but no solution (I don't want to remove JasperViewer.viewReport(jasperPrint) because it's trivial for me to display the report)

Jasper Report Generates a PDF and then Glassfish crashes/shutsdown


I don't want to remove JasperViewer.viewReport(jasperPrint) because it's trivial for me to display the report

JasperViewer.viewReport() will display the report locally (ie on the machine running Glassfish) and is useless for your remote users. What you need to do is send the PDF file from disk to the user so they can download and open it.

ALso take a look at: http://jasperreportjsf.sourceforge.net/web/index.html for JSF integration of JasperReports.


If the line

JasperViewer.viewReport(jasperPrint);

is causing the problem, you could try surrounding it in a try-catch-Throwable:

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

The important thing here is catching Throwable, which the top class of the Error/Exception hierarchy, so it catches everything. Particularly, it catches Errors, which are unchecked - I suspect you might be encountering one of those.

However, if the code inside that method calls System.exit(), you can use this nice workaround.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜