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".
source share