JasperReports:如何在jsp页面中调用报告 [英] JasperReports: How to call the report in jsp page
问题描述
我使用 iReport 3.7.4版本
制作了一个jasper报告,现在我必须使用它或在我的java应用程序中调用该报告,我使用的是servlet,jsp和struts框架,apache tomcat作为服务器。
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中编译报告
- 将编译后的报告放在类路径上
-
加载
- Compile the report in iReport
- Place the compiled report on the classpath
load it with
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屋!