Just a quick posting about an issue I was running in to that was solved pretty easily with a minimal amount of work. Providing it here as a tip for people new to JasperReports and using it to deliver HTML reports via the web.
The issue I was running in to was caching of report charts when outputting to HTML format. When JRHtmlExporter creates links to images in the report output it uses the format img_x_y_z[_z_z] where x, y, and z are as follows:
- x is the index of a document within the list of documents to export in batch mode.
- y is the page index.
- z values are a series of one or more element indexes that locate the image on the page,
looping through nested frames if needed.
(taken from the JasperReports Definitive Guide – pg. 197)
The issue is if you run a report which generates a chart and then rerun the report with similar parameters which doesn’t result in a change to the image name you will end up with a cached copy of the chart image…probably not what you want.
The solution is simple: when you define your IMAGES_URI paramter for the JRHtmlExporter tack on the current system time as follows:
In this example I’m using the system time to “randomize” the image url which makes sure that the images are always displayed properly. Note too that I’m using the image servlet that’s included as part of JasperReports.
I hope this helps someone. I was scratching my head for a bit over this one but the solution is pretty simple.