简体   繁体   English

Jasper报告生成PDF,然后Glassfish崩溃/关闭

[英]Jasper Report Generates a PDF and then Glassfish crashes/shutsdown

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? 我正在运行一个用JSF / Java开发的应用程序,当我让JasperReports ExporttoPDFFile开始工作并运行该应用程序时,将编译并显示jrxml,然后将其导出到一个pdf文件,该文件看上去应该和它完全一样。 JSF返回并加载了正确的页面,但是Glassfish 3停止工作,我必须启动或重新启动它,然后我才能继续使用该应用程序,一切正常,直到JasperReports编译并导出...任何想法?

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

JSF PAGE JSF页面

 <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>

code

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";
}

Disable the following line: 禁用以下行:

JasperViewer.viewReport(print);

Such as: 如:

//JasperViewer.viewReport(print);

I believe JasperViewer is the previewer that displays the printed report locally. 我相信JasperViewer是可在本地显示打印报告的预览器。 If this is running on a server, then the JasperViewer will try to access the video display of the server to show the report. 如果它在服务器上运行,那么JasperViewer将尝试访问服务器的视频显示以显示报告。 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();
  }
}

Find the code that calls reportGenerate and make it call reportGenerateNew . 查找调用reportGenerate的代码,并将其命名为reportGenerateNew Or wrap the code within the reportGenerate method with a try...catch . 或者使用try...catch将代码包装在reportGenerate方法中。 The exception that gets thrown will help you determine the source of the problem. 引发的异常将帮助您确定问题的根源。

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. 另外,如果您尝试将PDF文件写入Web浏览器,则必须使用HTTP响应流调用相应的JasperReports API方法(它是静态的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM