Jasper Report 生成 PDF,然后 Glassfish 崩溃/关闭
我正在运行一个用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
禁用以下行:
如:
我相信JasperViewer是本地显示打印报告的预览器。如果它在服务器上运行,那么 JasperViewer 将尝试访问服务器的视频显示以显示报告。此时服务器很可能会抛出异常。
要查找问题,请执行以下操作:
找到调用
reportGenerate
的代码并使其调用reportGenerateNew
。或者使用try...catch
将代码包装在reportGenerate
方法中。抛出的异常将帮助您确定问题的根源。另外,如果您尝试将 PDF 文件写入 Web 浏览器,则必须使用 HTTP 响应流调用相应的 JasperReports API 方法(它是静态的)。
Disable the following line:
Such as:
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:
Find the code that calls
reportGenerate
and make it callreportGenerateNew
. Or wrap the code within thereportGenerate
method with atry...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.