I would like to know how to generate reports using the Jasper IReports tool in a web application.
I have installed IReports and it is working fine. It can connect to the database and I have built some sample reports. My problem is I don’t know how to integrate these reports with my web application. Do I need to copy the .jasper files into my application classes folder or some other part of my web app?
Thanks in advance.
To integrate Jasper Reports (iReport is just a tool to design Jasper Reports) you need to include the following jars along with the Jasper Reports jar on your classpath:
For exporting to pdf you need:
(version 2.1.7 or later)
You may need other jars depending on what functionality you are using, so take a look at the Jasper Reports Requirements for any others you may need.
The easiest thing you can do to integrate the compiled versions of the reports you designed, will probably be to include them in the default package of your source. I actually prefer though to set up a new folder on the server to place the files in. The reason being is that if I need to update a report you can easily copy over a new compiled version of the report without having to redeploy the application.
Lastly your java code will return a byte array of the exported report to your front end. On the front end it is a matter of setting the headers correctly for the response type and returning the byte array. This is done differently in every framework, and so you should look into that for which ever one you are using.
As an example of how your java code could look to get the byte array: