【发布时间】:2020-08-07 15:54:29
【问题描述】:
我正在为我的报告引擎使用 JSP 和 JasperReports 开发 Java Web 应用程序。我使用 AWS ELB 作为应用程序服务器。
我不确定应该将 .jasper 文件放在哪里以及如何访问它。
我的项目结构:
我试过了:
- 在 Web 文件夹中创建文件夹并将 .jasper 放入其中。我用下面的代码访问它
String jasperPath = "\\report\\TestPengguna.jasper";
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperPath, new HashMap(), JConnectionUtil.con);
JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());
- 将 .jasper 放到 Web 文件夹中,像这样访问它
String jasperPath = "\\TestPengguna2.jasper";
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperPath, new HashMap(), JConnectionUtil.con);
JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());
- 使用此代码访问它
String jasperPath = "\\report\\TestPengguna.jasper";
ClassLoader cl = this.getClass().getClassLoader();
JasperPrint jasperPrint = JasperFillManager.fillReport(cl.getResourceAsStream(jasperPath), new HashMap(), JConnectionUtil.con);
JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());
更新:使用 Alex K 提供的链接解决此问题。谢谢
【问题讨论】:
-
嗨,Alex K,非常感谢。我的问题可以从您提供的链接中得到解答。
标签: java jasper-reports amazon-elastic-beanstalk war