gpt4 book ai didi

java - 如何在 HTML 页面中显示 Jasper 报告

转载 作者:行者123 更新时间:2023-12-02 06:15:33 25 4
gpt4 key购买 nike

所以,我已经制作了报告,但问题是我正在使用 GetMapping 来显示,并且它单独在另一个页面上打开,但我需要它在 div、表格、卡片或甚至是模态。它只是无法从上一页更改。

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

Controller 上的方法

@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

最佳答案

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

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

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

关于java - 如何在 HTML 页面中显示 Jasper 报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55874663/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com