Java Reference
In-Depth Information
Directing the browser to the URL for this servlet will result in the report being
displayed in the browser in HTML, as can be seen in the following screenshot:
We chose to export this particular report to illustrate that the HTML exporting
capability works fine for more complex reports. This report generates charts at fill
time, which get translated to image files when exporting to HTML.
In order to stream a report as HTML to the browser, we need to set some parameters
as an instance of
net.sf.jasperreports.engine.export.JRHtmlExporter
.
The first parameter name is defined in the
net.sf.jasperreports.engine.
JRExporterParameter.JASPER_PRINT
constant. Its value must be an instance of
net.sf.jasperreports.engine.JasperPrint
containing the report we wish to
stream to the browser. The next parameter we need to set is defined in the
net.
sf.jasperreports.engine.JRExporterParameter.OUTPUT_WRITER
constant,
as can be seen in the example. Its corresponding value must be the instance of
java.io.PrintWriter
obtained by calling the
getWriter()
method on the
HttpServletResponse
object.