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?
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 "quer开发者_如何学运维ies";
}
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.
精彩评论