5.把报表集成到Web应用程序中-生成网页和导出两种方式

转自:https://wenku.baidu.com/view/104156f9770bf78a65295462.html

第四部分,把报表集成到Web应用程序中

用MyEclipse新建一个Web Project,在WebRoot下新建一个reports文件夹,用来放ireport生成的jasper文件

找到前边保存ireport报表的路径,报表在预览后,生成jasper文件,如图

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKkAAABWCAIAAAA7cyG0AAAgAElEQVR4nO2deVxTV/r/Y5127G/GzjjTdVpb27q0LnUB9w1lF5BNQECLgCJuqOCuCIoiKiCLoIKKIpvgwi77EkIIIawBwpIEspGFJKxJCLn3Pr8/Au62Ap1O/Zbn9Xn5wpvzPOfc8849956bc5+Lg3H7sxruf92Acfuf2Tj7P6+Ns//z2jj7P6+Ns//zGg55swFARUWFgM9HUUQ1OIioBhFEhaIIiiIAMDCgEPD5lRQKlUoFgNf4YwCIjJ3oMXNTaG3fIAD2C3W9YCqlrFvSp1ChGKYa5BNv7J73rylTpnz0vZZjQtMgBsON6yk4vt7UI4LcCSOI/eexsbInk8n8Dh6KqAYHlS/hR1EEwzAGg15TU/MKe+xpBZLUY7OG2aPP14y9sX2YsiFiy4IzOTIAYDekXTmZzJbJZLKmhENuTjujGRgAqq4FRbFXKxxuC/rCJvSlIgAA2HCYlwq+VPJd/VqNlT2JROLxuIhqUKkcGFQ+hx8ZOvqZTMYr7AEAFTVUlpYQCPj8FF+H7y1C6/pVAIANChtK8Hg8vrSWLlYCoGgPn8mX8NhNjeV4PL6U1NY1CNDfWhi1d9UXm8+nlzYK5KpBpXJoN+rvXD7mdLZMOYxjsKeDzhV1yxEEA1VnY3kpHo8vragVDQCgGGBKKbuagMfj8SQqvVOJon18Bl/CY9MahutSYhiGogDQyyQR8Hh8CbmW3QeAoTIJjy9o47IYZHxlq7APRVH0v0rpv2NjZU8kErkcjmpwUDmgeIpfNYwfABgMelVV1XPsURSUnfXRR9es1tDQ1NRYMPWfH3xuFEQbxAZlgop75xxX6+jo6KwytQ9IbelGg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RR39b/Gy3T+o4XA4Ly+vEbNHEESlUvF4vJLS0no8XkIkCohEvvpfEonNYLL4/A4eTyAQ8Dv4HR0dvb29I+8iFEWRbk5jK4P9GwyIKKpS9nBpVW3iARUyhmAoig72cBoImVnFDaw+GMO36H9uXl5eavZP7aWh7Y3s3/RWxNfaqG95Pz+cjtXQ3yrWs/H/3QWPvO64f1v24/au26vn+3H2fxb79fn92w/s4/Z/zMbZ/3ltnP2f18bZ/3ltnP2f1/4/M+E/KfB5h7gAAAAASUVORK5CYII=" alt="" />

把这个deptReport.jasper文件复制到Web项目里的reports文件夹中

导入JasperReport的包,包可以从以下路径找到.

Ireport安装路径\iReport-3.7.6\ireport\modules\ext

把这里所有的包引到Web项目里,引入oracle的jdbc驱动,接下来进行编程,以Servlet为例

1,生成报表并且以HTML形式在网页上显示

Servlet的主要逻辑代码如下:

 request.setCharacterEncoding("utf-8");
// 接收查询参数,将来这个参数就是我们在报表中定义的parDname
String deptName = request.getParameter("dname"); // 报表文件路径,我们用ireport做的jasper文件路径
// JasperReport需要jasper文件的真实路径
String reportPath = request.getSession().getServletContext()
.getRealPath("/reports/deptReport.jasper");
// 报表参数,jasper文件可能不只一个参数
// 在程序里,用一个Map对象,向jasper文件传递他需要的参数
Map reportParameters = new HashMap();
reportParameters.put("parDname", deptName);
// 报表连数据库所用的数据连接
// 因为报表直接以数据库为数据源,所以在这里需要给jasper文件一个jdbc连接
Connection con = null;
// 清空响应流
response.reset();
// 设置输出格式
response.setContentType("application/html");
// 创建JDBC连接
Class.forName("oracle.jdbc.OracleDriver");
con = DriverManager.getConnection(
"jdbc:oracle:thin:@oracle10:1521:oracle", "scott", "tiger");
// JasperReport提供的类,用于生成一个HTML文件
JasperRunManager.runReportToHtmlFile(reportPath, reportParameters, con);
response.sendRedirect(request.getContextPath()
+ "/reports/deptReport.html");
/*
* 如果要在网页上显示PDF文件,把前两句去掉,放开这段注释
* ServletOutputStream out = response.getOutputStream();
* //从jasper报表生成PDF字节
* byte[] pdfBytes = JasperRunManager.runReportToPdf(reportPath, reportParameters, con);
* //设置输出内容长度
* response.setContentLength(pdfBytes.length); //将PDF写入报表
* out.write(pdfBytes, 0, pdfBytes.length);
* out.flush();
* out.close();
*/ // 关闭数据连接
con.close();

这里只写出逻辑代码,实际用的时候,加上各种异常的处理。

2,         导出PDF和Excel文件

Servlet的逻辑代码如下,还是没写异常处理,开发时加上

 // 接收查询参数
request.setCharacterEncoding("utf-8");
String deptName = request.getParameter("dname");
// 在请求的时候多加一个参数,标识要生成文件的格式是xls还是pdf
String format = request.getParameter("format");
// 报表文件路径
String reportPath = request.getSession().getServletContext()
.getRealPath("/reports/deptReport.jasper");
// 报表参数
Map reportParameters = new HashMap();
reportParameters.put("parDname", deptName);
// 报表查数据库的连接
Connection con = null;
// 清空响应流
response.reset();
// 设置输出格式
String contentType = "pdf";
if ("xls".equals(format.toLowerCase())) {
contentType = "xls";
}
response.setContentType("application/" + contentType);
// 设置输出文件名
response.setHeader("Content-Disposition",
"attachment; filename=deptReport." + contentType);
// 输出流,用于向浏览器传送pdf文件
ServletOutputStream out = null;
// 创建数据连接
Class.forName("oracle.jdbc.OracleDriver");
con = DriverManager.getConnection(
"jdbc:oracle:thin:@oracle10:1521:oracle", "scott", "tiger");
// 取响应流
out = response.getOutputStream();
// 创建导出器,JasperReport提供的类
// 这里以xls和pdf为例,如果需要生成其他格式的文件,用其他导出器就行
JRAbstractExporter exporter = new JRRtfExporter();
// PDF导出器
if ("pdf".equals(format.toLowerCase())) {
exporter = new JRPdfExporter();
} else if ("xls".equals(format.toLowerCase())) { // excel导出器
exporter = new JRXlsExporter();
exporter.setParameter(
JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, false);
}
// 加载报表文件
JasperReport report = (JasperReport) JRLoader.loadObject(reportPath);
// 创建JasperPrint对象
JasperPrint jasperPrint = JasperFillManager.fillReport(report,
reportParameters, con);
// 设置要输出的jasper对象
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
// 设置输出流
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
// 导出
exporter.exportReport();
out.flush();
out.close();
con.close();

到此为止,JasperReport + ireport 集成报表到Web程序的一般步骤就说完了,本说明中所提到的报表源文件及Web示例,随文档一起,可以参实际例子来学习Jasper 和 ireport

上一篇:POJ 1458 Common Subsequence (DP+LCS,最长公共子序列)


下一篇:java类 对象 和构造方法