Jasper报告生成PDF然后Glassfish崩溃/关闭 [英] Jasper Report Generates a PDF and then Glassfish crashes/shutsdown

查看:111
本文介绍了Jasper报告生成PDF然后Glassfish崩溃/关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行我在JSF / Java中开发的应用程序,当我让JasperReports ExporttoPDFFile开始工作并运行应用程序时,jrxml被编译并显示,然后导出到pdf文件,看起来与它完全一样应该和JSF返回正确的页面并加载,但Glassfish 3停止工作,我必须启动或重新启动它才能继续再次使用该应用程序,一切正常,直到JasperReports编译和导出...任何想法?

I am running an app I have developed in JSF/Java and as soon as I got JasperReports ExporttoPDFFile to start working and ran the app, the jrxml is compiled and displayed, then exported to a pdf file, that looks exactly as it should and the proper page is returned by the JSF and loads but then Glassfish 3 stops working and I have to start or restart it before I can continue to use the app again, everything works fine until the JasperReports compile and export... any ideas?

http://pastebin.com/mPwYvWh9 < ---运行/崩溃后的Glassfish服务器日志

http://pastebin.com/mPwYvWh9 <--- Glassfish server log after running/crashing

JSF PAGE

 <ui:define name="content">
         <f:view>
            <h:form styleClass="form_option">

               <h:outputLabel value="Enter a query:"/>
               <h:inputText value="#{controls.sql}" />
               <h:commandButton action="#{controls.make}" value="Query"/>

               <h:commandButton action="#{controls.reportGenerate}" value="Generate Report"/>

            </h:form>
            <br />
           <h:form styleClass="form_option">
         <h:outputLabel value="Choose a Query or Report on the Left"/>

          <h:outputText escape="false" value=""/>


          </h:form>

        </f:view>
     </ui:define>

代码

public String reportGenerate()
       throws JRException, ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException{

    String connectionURL = "jdbc:oracle:thin:@server:1521:ora";
    String dbDriver = "oracle.jdbc.driver.OracleDriver";

    Class.forName(dbDriver).newInstance();

    Connection connection = DriverManager.getConnection(connectionURL, "PLANT", "PLANT");

    JasperDesign design = JRXmlLoader.load("C:\\Projects\\WebApplication8\\web\\uploads\\TutorialSub_1.jrxml");

    JasperReport jasperReport = JasperCompileManager.compileReport(design);

    JasperPrint print = JasperFillManager.fillReport(jasperReport, null, connection);

    JasperViewer.viewReport(print);

    JasperExportManager.exportReportToPdfFile(print, "C:\\Projects\\WebApplication8\\web\\uploads\\TutorialSub_1.pdf");

return "queries";
}


推荐答案

禁用以下行:

JasperViewer.viewReport(print);

例如:

//JasperViewer.viewReport(print);

我相信JasperViewer是在本地显示打印报告的预览器。如果这在服务器上运行,则JasperViewer将尝试访问服务器的视频显示以显示报告。有可能服务器此时会抛出异常。

I believe JasperViewer is the previewer that displays the printed report locally. If this is running on a server, then the JasperViewer will try to access the video display of the server to show the report. Chances are the server will throw an exception at this point.

要找到问题,请执行以下操作:

To find the problem, do this:

public String reportGenerateNew() {
  try {
    // Trap and print any errors or exceptions from the existing code.
    reportGenerate();
  }
  catch( Exception e ) {
    e.printStackTrace();
  }
}

查找调用的代码reportGenerate 并将其调用 reportGenerateNew 。或者使用 try ... catch 将代码包装在 reportGenerate 方法中。抛出的异常将帮助您确定问题的根源。

Find the code that calls reportGenerate and make it call reportGenerateNew. Or wrap the code within the reportGenerate method with a try...catch. The exception that gets thrown will help you determine the source of the problem.

此外,如果您尝试将PDF文件写入Web浏览器,则必须使用HTTP响应流调用相应的JasperReports API方法(它是静态的)。

Also, if you are trying to write the PDF file to a web browser, you will have to call the corresponding JasperReports API method (it is static) with the HTTP response stream.

这篇关于Jasper报告生成PDF然后Glassfish崩溃/关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆