【问题标题】:Where should i put my .jasper file and how to access it? [duplicate]我应该把我的 .jasper 文件放在哪里以及如何访问它? [复制]
【发布时间】:2020-08-07 15:54:29
【问题描述】:

我正在为我的报告引擎使用 JSP 和 JasperReports 开发 Java Web 应用程序。我使用 AWS ELB 作为应用程序服务器。

我不确定应该将 .jasper 文件放在哪里以及如何访问它。

我的项目结构:

我试过了:

  1. 在 Web 文件夹中创建文件夹并将 .jasper 放入其中。我用下面的代码访问它
String jasperPath = "\\report\\TestPengguna.jasper";
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperPath, new HashMap(), JConnectionUtil.con);
JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());
  1. 将 .jasper 放到 Web 文件夹中,像这样访问它
String jasperPath = "\\TestPengguna2.jasper";
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperPath, new HashMap(), JConnectionUtil.con);
JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());
  1. 使用此代码访问它
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 提供的链接解决此问题。谢谢

【问题讨论】:

标签: java jasper-reports amazon-elastic-beanstalk war


【解决方案1】:

jasper 文件的全部意义在于它们与您的项目分开编译,并且可以在出现格式问题或风格干预时进行编辑哈哈。我将编译好的 jasper 文件保存在运行项目的服务器的 opt 文件夹中,并像 opt/someFolder/report/TestPengguna.jasper 一样访问它。我使用 jaspersoft studio app 编译和编辑 this

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-14
    • 2016-05-23
    • 1970-01-01
    • 2010-12-01
    • 2018-09-28
    • 2019-10-04
    • 1970-01-01
    相关资源
    最近更新 更多