[英]Jasper Report Generates a PDF and then Glassfish crashes/shutsdown
我正在运行一个用JSF / Java开发的应用程序,当我让JasperReports ExporttoPDFFile开始工作并运行该应用程序时,将编译并显示jrxml,然后将其导出到一个pdf文件,该文件看上去应该和它完全一样。 JSF返回并加载了正确的页面,但是Glassfish 3停止工作,我必须启动或重新启动它,然后我才能继续使用该应用程序,一切正常,直到JasperReports编译并导出...任何想法?
http://pastebin.com/mPwYvWh9 <---运行/崩溃后的Glassfish服务器日志
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>
码
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将尝试访问服务器的视频显示以显示报告。 服务器可能会在此时抛出异常。
要找到问题,请执行以下操作:
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方法(它是静态的)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.