![](/img/trans.png)
[英]JasperReport with spring MVC : print report on client side without displaying it
[英]Glassfish shutdown after displaying a report using jasperReport
我正在使用JSF开发一个应用程序,并且正在使用Glassfish服务器,该应用程序使用jasperReport生成报告,该应用程序运行良好并生成报告(pdf格式),这些报告存储在磁盘上,问题是我使用时
JasperViewer.viewReport(jasperPrint);
向用户显示报告,然后尝试继续使用我的应用程序,该应用程序不起作用,我应该重新运行该应用程序!
在控制台上,错误是:
Completed shutdown of Log manager service
我的代码:
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();
}
我应该怎么做才能解决这个问题?
ps:我在堆栈流上发现了同样的问题,但是没有解决方案(我不想删除JasperViewer.viewReport(jasperPrint),因为它对于我来说显示报告很简单)
我不想删除JasperViewer.viewReport(jasperPrint),因为对我来说显示报告很简单
JasperViewer.viewReport()
将在本地(即在运行Glassfish的计算机上JasperViewer.viewReport()
显示报告,并且对远程用户没有用。 您需要做的是将PDF文件从磁盘发送给用户,以便他们下载并打开它。
还可以查看: http : //jasperreportjsf.sourceforge.net/web/index.html,用于JasperReports的JSF集成。
如果行
JasperViewer.viewReport(jasperPrint);
导致此问题,您可以尝试将其围绕在try-catch-Throwable中:
try {
JasperViewer.viewReport(jasperPrint);
} catch (Throwable t) {
t.printStackTrace();
}
这里重要的是捕获Throwable ,它是Error / Exception层次结构的顶级类,因此它捕获了所有内容 。 特别是,它捕获了未经检查的错误-我怀疑您可能会遇到其中之一。
但是,如果该方法中的代码调用System.exit()
,则可以使用此不错的解决方法 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.