java - 如何在 HTML 页面中显示 Jasper 报告
问题描述
所以,我已经制作了报告,但问题是我正在使用 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;
}
解决方案
我使用 iframe 解决了这个问题,但是我没有在 src="" 上传递 HTML,而是在我的表单中针对 iframe 的名称在按钮上创建了一个 onClick 函数。
<iframe name="my_iframe" src=""></iframe>
<button onclick="this.form.target='my_iframe'">My Button</button>
推荐阅读
- flutter - 使用颤振触发警报时运行本机代码
- python - 用于寻找导数转折点的python方程,同时也最有效地使用成本
- c# - 查看哈希集中的字符串是否包含来自另一个哈希集中的元素的最佳方法?C#
- types - OCaml 期望在模式匹配期间不会出现在任何地方的模式
- reactjs - 根据对象中的多个键/值对将Antd单选按钮设置为选中?
- ffmpeg - 创建静音 wav 并通过管道传输它
- kubernetes - 测试使用 operator-sdk 搭建的操作员时,Scheme 为 Nil
- java - 是否可以在 REST 控制器中使用 @Parameter?
- mongock - 如何减少 mongock 脚本获取锁所需的时间?
- php - WP 无法使用带有 Plesk 的 Google Cloud Server 访问 api.wordpress.org