Jasper reports primer

本文介绍了JasperReports的两种使用方式:通过安装JasperServer进行报告管理和直接在应用程序中集成JasperReports库来生成报告。文章详细阐述了报告生成过程,包括创建模板、填充报告及导出为PDF或Excel等格式。

1. You have two ways to use Jasper reports, one is to download and installe the Jaser Server and use it. It'll install Tomcat and by default PostgreSql, and an web application for managing your reports. The other way is to include Jasper reports libs in your application and manage the report generation and export programmatically by yourself.

 

2. Jasper report generation include these steps: create template (.jrxml), compile template (.jasper), fill report template (.jrprint), and then save the report to disk/ or export to other format/media, such as web application pages.

 

3. Jasper repot template normally generated with a tool, such as iReports.

But the template generated by IReport normally has the SQL query embedded inside the xml template. You can remove the query section and recomile it to get the .jasper file. You can create your own data source and fill the report accordingly, like by a JRResultSetDataSource. This way, you move the DAO to your own program and control it programmtically.

 

4. To fill a comipled Jasper report template:

JasperFillManager.fillReportToFile(String sourceFile, String destFile, Map params, JRDataSource ds);

 

5. To export a Jasper report to PDF as one go: (it can be jdbc or JPA)

 

String sql = "ur query";

Connection conn = DAOUtil.getConnection(dsname);

ResultSet resultSet = ....

JRResultSetDataSource ds = new JRResultSetDataSource(resultSet);

 

JasperRunManager.runReportToPdsStream(rptAsInStream, outputStream, new HashMap(), ds);

statement.close();

resultSet.close();

conn.close();

 

// if jsf, you wanna break its life cycle

FacesContext fc = FacesContext.getCurrentInstance();

fc.responseComplete();

 

// if http, you wanna set header(s) here

// response.setContenType("application/pdf");


outputStream.flush();

outputStream.close();

 

6. The normal steps to export to a pdf file:

 

File file = new File("/report/myReport.jrprint");

try {

JasperPrint jasperPrint = (JasperPrint) JRLoader.loadObject(file);

JRPdfExporter pdfExporter = new JRPdfExporter();

pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

pdfExporter.setParameter(JRExporterOUTPUT_FILE_NAME, "/export/myReport.pdf");

pdfExporter.exportReport();

 

}

catch(Exception e) {

e.printStacktrace();

}

 

7. It's similar to export to Excel file:

 

File file = new File("/report/myReport.jrprint");

try {

JasperPrint jasperPrint = (JasperPrint) JRLoader.loadObject(file);

JExcelApiExporter xlsExporter = new JExcelApiExporter ();

xlsExporter .setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

xlsExporter .setParameter(JRExporterOUTPUT_FILE_NAME, "/export/myReport.xls");

xlsExporter .exportReport();

 

}

catch(Exception e) {

e.printStacktrace();

}

 

Note: it's preferable to use JExcelApiExporter, which is the newer implementation of Excel exporter. The original JrXlsExporter is does not support exporting images.

 

That's all for an introduction to Jasper report (-;

 

随着信息技术在管理上越来越深入而广泛的应用,作为学校以及一些培训机构,都在用信息化战术来部署线上学习以及线上考试,可以与线下的考试有机的结合在一起,实现基于SSM的小码创客教育教学资源库的设计与实现在技术上已成熟。本文介绍了基于SSM的小码创客教育教学资源库的设计与实现的开发全过程。通过分析企业对于基于SSM的小码创客教育教学资源库的设计与实现的需求,创建了一个计算机管理基于SSM的小码创客教育教学资源库的设计与实现的方案。文章介绍了基于SSM的小码创客教育教学资源库的设计与实现的系统分析部分,包括可行性分析等,系统设计部分主要介绍了系统功能设计和数据库设计。 本基于SSM的小码创客教育教学资源库的设计与实现有管理员,校长,教师,学员四个角色。管理员可以管理校长,教师,学员等基本信息,校长角色除了校长管理之外,其他管理员可以操作的校长角色都可以操作。教师可以发布论坛,课件,视频,作业,学员可以查看和下载所有发布的信息,还可以上传作业。因而具有一定的实用性。 本站是一个B/S模式系统,采用Java的SSM框架作为开发技术,MYSQL数据库设计开发,充分保证系统的稳定性。系统具有界面清晰、操作简单,功能齐全的特点,使得基于SSM的小码创客教育教学资源库的设计与实现管理工作系统化、规范化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值