In previous chapters, we have seen examples of generating a PDF report and streaming it to the browser on the fly. Earlier in this chapter, we saw how to export reports to an HTML format and store it in the file system. In this section, we will cover how to export a report to HTML and immediately send it to the user's browser window. The following example is a servlet that exports an already filled JasperPrint
object to HTML and displays the resulting exported report to the browser. As can be seen from the code, it takes the base report name as a request parameter. Executing this report using the BarChartDemoReport
from Chapter 7 results in the following page displayed in the browser.
package net.ensode.jasperbook; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest...