[英]Glassfish shutdown after displaying a report using jasperReport
I am developping an application using JSF and I am using the Glassfish server ,this application generate report using jasperReport,the application work fine and generate reports(pdf format) ,those reports are stored on my disk,the problem is when I use 我正在使用JSF开发一个应用程序,并且正在使用Glassfish服务器,该应用程序使用jasperReport生成报告,该应用程序运行良好并生成报告(pdf格式),这些报告存储在磁盘上,问题是我使用时
JasperViewer.viewReport(jasperPrint);
to display the report to the user and then try to continue using my application it didn't work ,I should re-run the application! 向用户显示报告,然后尝试继续使用我的应用程序,该应用程序不起作用,我应该重新运行该应用程序!
On the console the error is: 在控制台上,错误是:
Completed shutdown of Log manager service
My code: 我的代码:
public void fillReport() throws ParseException, groovyjarjarcommonscli.ParseException {
try {
// - Connexion à la base
Driver monDriver = new com.mysql.jdbc.Driver();
DriverManager.registerDriver(monDriver);
connection = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/Mybase", "root", "root");
// - Chargement et compilation du rapport
JasperDesign jasperDesign = JRXmlLoader.load("C:/Documents and Settings/report2.jrxml");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
Map parameterMap = new HashMap();
parameterMap.put("DateFrom", formatingDateTime(date1));
parameterMap.put("DateTo", formatingDateTime(date2));
parameterMap.put("SQL", Createquery());
// // - Execution du rapport
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameterMap, connection);
JasperViewer.viewReport(jasperPrint);
JasperExportManager.exportReportToPdfFile(jasperPrint,"C:/Documents and Settings/report2.pdf");
} catch (JRException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
connection.close();
}
What should I do to resolve this problem? 我应该怎么做才能解决这个问题?
Ps:I have found the same problem on stackflow but no solution (I don't want to remove JasperViewer.viewReport(jasperPrint) because it's trivial for me to display the report) ps:我在堆栈流上发现了同样的问题,但是没有解决方案(我不想删除JasperViewer.viewReport(jasperPrint),因为它对于我来说显示报告很简单)
Jasper Report Generates a PDF and then Glassfish crashes/shutsdown Jasper报告生成PDF,然后Glassfish崩溃/关闭
I don't want to remove JasperViewer.viewReport(jasperPrint) because it's trivial for me to display the report
我不想删除JasperViewer.viewReport(jasperPrint),因为对我来说显示报告很简单
JasperViewer.viewReport()
will display the report locally (ie on the machine running Glassfish) and is useless for your remote users. JasperViewer.viewReport()
将在本地(即在运行Glassfish的计算机上JasperViewer.viewReport()
显示报告,并且对远程用户没有用。 What you need to do is send the PDF file from disk to the user so they can download and open it. 您需要做的是将PDF文件从磁盘发送给用户,以便他们下载并打开它。
ALso take a look at: http://jasperreportjsf.sourceforge.net/web/index.html for JSF integration of JasperReports. 还可以查看: http : //jasperreportjsf.sourceforge.net/web/index.html,用于JasperReports的JSF集成。
If the line 如果行
JasperViewer.viewReport(jasperPrint);
is causing the problem, you could try surrounding it in a try-catch-Throwable: 导致此问题,您可以尝试将其围绕在try-catch-Throwable中:
try {
JasperViewer.viewReport(jasperPrint);
} catch (Throwable t) {
t.printStackTrace();
}
The important thing here is catching Throwable , which the top class of the Error / Exception hierarchy, so it catches everything . 这里重要的是捕获Throwable ,它是Error / Exception层次结构的顶级类,因此它捕获了所有内容 。 Particularly, it catches Errors, which are unchecked - I suspect you might be encountering one of those.
特别是,它捕获了未经检查的错误-我怀疑您可能会遇到其中之一。
However, if the code inside that method calls System.exit()
, you can use this nice workaround . 但是,如果该方法中的代码调用
System.exit()
,则可以使用此不错的解决方法 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.