java - Jasper-Report服务器端保存

标签 java gwt tomcat jasper-reports

我必须在服务器端 (Tomcat + gwt) 创建一个 JasperReport。 我尝试运行一个 hello-world

public class AuthorReport {
 public static void generate() {
try {
  String reportSource = "resources/authorReport.jasper";

  JasperReport jasperReport = JasperCompileManager
    .compileReport(reportSource);

  JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
    new HashMap(), new JREmptyDataSource());

  JasperExportManager.exportReportToHtmlFile(jasperPrint, "hello_report.html");


} catch (Exception e) {
  e.printStackTrace();
}
}
}

我没有发现异常,但我无法意识到生成的文件在哪里以及是否生成了它。

也许我必须以某种方式集成 Tomcat 和 JasperReports?

最佳答案

您必须在 JasperFillManager.fillReport 的第二个参数中指定此位置。

public class AuthorReport {

    public static void generate() {
        try {
           String reportSource = "resources/authorReport.jasper";

           JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);

           Map<String, Object> params = new HashMap<String, Object>();
           params.put(JRParameter.REPORT_FILE_RESOLVER, new SimpleFileResolver(new File(youPath)));

           JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource());

           JasperExportManager.exportReportToHtmlFile(jasperPrint, "hello_report.html");
       } catch (Exception e) {
           e.printStackTrace();
       }
   }
}

祝你好运!

关于java - Jasper-Report服务器端保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9803311/

相关文章:

java - 使用自定义处理程序的 GWT 远程日志记录

tomcat - 更改tomcat中的webapp名称

javascript - 如何将 GWT 应用程序集成到另一个 Web 框架中?

python - 在 Tomcat 7 上安装并运行 CGI 代理 Python

angular - 在 Tomcat Apache 生产服务器中部署 Angular 7 PWA 应用程序

java - cplex java,未找到解决方案;如何使用exportModel()改进程序

java - 不支持的 major.minor 版本 52.0 错误

java - Java中用于保存存储桶列表ID的默认结构

java - 如何在不使用 Eclipse 的情况下调试 gwt 应用程序

java - 有没有使用 GWT 解析 HTML 的工具