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

发布于 2024-10-19 02:57:27 字数 2022 浏览 2 评论 0原文

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

http://pastebin.com/mPwYvWh9 <--- 运行/崩溃

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>

代码后的 Glassfish 服务器日志

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听闻余生 2024-10-26 02:57:27

禁用以下行:

JasperViewer.viewReport(print);

如:

//JasperViewer.viewReport(print);

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

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

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 方法中。抛出的异常将帮助您确定问题的根源。

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

Disable the following line:

JasperViewer.viewReport(print);

Such as:

//JasperViewer.viewReport(print);

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

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文