I made one jasper report using ireport3.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. I want steps regarding how to call the jasper report with some example.
This piece of code should give you some idea on how to do it
JasperReport jr=JasperCompileManager.compileReport("yourJRXMLFilePath");
JasperPrint jrPrint = JasperFillManager.fillReport(jr,mapWithParameters,aJRDataSource);
JasperExportManager.chooseYourFavoriteMethod(jrPrint,"destinationFile");
Otherwise, check the api The first line can be ommited if you had already compiled the file with iReport. Check the api for the correct method on JasperFillManager in this case.
- Compile the report in iReport
- Place the compiled report on the classpath
load it with
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(inputStream);
Fill it with data.
dataSource
is theDataSource
instance you have - for example aBeanCollectionDataSource
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, dataSource);
Export it
JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream); exporter.exportReport();
The
outputStream
above may be either aresponse.getOutputStream()
or aFileOutputStream()
, 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 theContent-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.