JasperReports:如何在jsp页面中调用报表 [英] JasperReports: How to call the report in jsp page
问题描述
我使用 iReport 3.7.4 版本
制作了一份 jasper 报告,现在我必须使用该报告或在我使用 servlet、jsp 和 struts 框架的 java 应用程序中调用该报告作为服务器.
I made one jasper report using iReport 3.7.4 version
, now i have to use that or call that report in my java application where i am using servlets, jsp and struts framework, apache tomcat as server.
我想要有关如何通过一些示例调用 jasper 报告的步骤.
I want steps regarding how to call the jasper report with some example.
推荐答案
- 在 iReport 中编译报告
- 将编译后的报告放在类路径上
用
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(inputStream);
用数据填充它.dataSource
是您拥有的 DataSource
实例 - 例如一个 BeanCollectionDataSource
Fill it with data. dataSource
is the DataSource
instance you have - for example a BeanCollectionDataSource
JasperPrint jasperPrint =
JasperFillManager.fillReport(jasperReport, params, dataSource);
导出
Export it
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
exporter.exportReport();
上面的 outputStream
可以是 response.getOutputStream()
或 FileOutputStream()
,这取决于你是否想要将其发送给客户端,或者您想将其存储为文件.如果要将其发送给客户端,则必须发送 Content-Disposition
标头,以及其他一些标头,但这取决于要保存的格式.如果您想在客户端打印,这是一个完全不同的问题 - 您需要一些客户端代码,例如一个小程序.
The outputStream
above may be either a response.getOutputStream()
or a FileOutputStream()
, depending on whether you want to send it to a client or you want to store it as a file. If you want to send it to the client, you'd have to send the Content-Disposition
header, and some more, but that depends on the format you want to save to. In case you want to print on the client, it's quite a different question - you'd need some client-side code, an applet, for example.
这篇关于JasperReports:如何在jsp页面中调用报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!