How to export JasperReport to HTML?

I created one .jasper file for my project. I get the output in a JasperViewer window, but instead want to see it in the HTML output form. How can i do this?

+5
source share
2 answers

The Jasper report project comes with sample code for exporting reports to HTML. This is not only one HTML file, but at least it requires a transparent 1x1 gif used for decoration. Exporting reports to HTML files is not recommended due to portability and printing issues. However, you can display HTML reports inside your web server (which is very useful) using this sample code. See the \ demo \ samples \ webapp application for more details.

+3
source

The following code will generate an HTML report:

private DataSource jasperDataSource; private String jasperReportDir; public void generateHtmlReport(String reportPath, String reportCode, String outputLocation, Map<String, Object> params) throws Exception { Connection connection=null; try { connection = jasperDataSource.getConnection(); JasperReport jasperReport = (JasperReport) JRLoader.loadObject(jasperReportDir + "/" + reportPath + "/" + reportCode + ".jasper"); params.put(JRParameter.REPORT_FILE_RESOLVER, new SimpleFileResolver(new File(jasperReportDir + "/" + reportPath))); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, connection); JasperExportManager.exportReportToHtmlFile(jasperPrint,outputLocation +reportCode+".html"); } finally { if (connection!=null) { connection.close(); } } } 

Exports the generated report object to HTML format, placing the result in the second file parameter.

Images are placed as separate files inside the directory with the same name as the HTML destination file, plus the suffix "_files".

+3
source

Source: https://habr.com/ru/post/956176/


All Articles