【问题标题】:How to display a Jasper Report inside a HTML page如何在 HTML 页面中显示 Jasper 报告
【发布时间】:2019-05-02 01:13:34
【问题描述】:

所以,我已经制作了报告,但问题是我正在使用 GetMapping 进行显示,它单独在另一个页面上打开,但我需要它在 div、表格、卡片或甚至是模态的。它只是不能改变上一页。

我不知道如何在不重定向页面的情况下打开它。任何建议表示赞赏

控制器上的方法

@GetMapping("/seguro")
    public void export(HttpServletResponse response) throws IOException, JRException, SQLException {
        response.setContentType("text/html");
        JasperPrint jasperPrint = null;
        jasperPrint = seguroReportService.generatePromissoria(1L);
        HtmlExporter htmlExporter = new HtmlExporter(DefaultJasperReportsContext.getInstance());
        htmlExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
        htmlExporter.setExporterOutput(new SimpleHtmlExporterOutput(response.getWriter()));
        htmlExporter.exportReport();
    }

获取报告文件的方法

public JasperPrint generatePromissoria(Long id) throws SQLException, JRException, IOException {
        Connection conn = jdbcTemplate.getDataSource().getConnection();

        String path = resourceLoader.getResource("classpath:/reports/SeguroReport.jrxml").getURI().getPath();

        JasperReport jasperReport = JasperCompileManager.compileReport(path);
        // Parameters for report
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("titulo", "Relatório de Seguros");
        parameters.put("ID", id);

        JasperPrint print = JasperFillManager.fillReport(jasperReport, parameters, conn);

        return print;
    }

page where is supposed to open the report

Report opening in another page

【问题讨论】:

  • 你在web端使用什么? jQuery、Angular、试图放入 iFrame 等?基于此,有不同的方法。
  • @kendavidson 我是新手,不知道能否回答您的问题,但我使用的是弹簧和百里香叶。我去看看iframe,看起来很有趣。
  • 确保写下你为解决它所做的工作。

标签: java html spring jasper-reports thymeleaf


【解决方案1】:

我使用 iframe 解决了这个问题,但我没有在 src="" 上传递 HTML,而是在我的表单中针对 iframe 的名称在按钮上创建了一个 onClick 函数。

<iframe name="my_iframe" src=""></iframe>

<button onclick="this.form.target='my_iframe'">My Button</button>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-29
    • 2022-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多