Java Reference
In-Depth Information
Notice that for this example, we loaded an already filled report from the file system
and streamed it to the browser as HTML. It is also possible to load a Jasper template,
fill it, then export the resulting report to HTML, and stream it to the browser. To
accomplish this, we would load the Jasper template from the file system, fill it using
the JasperFillManager.fillReport() method, and then export the resulting
JasperPrint object to HTML. The following example is a modified version of the
previous servlet. This new version illustrates this procedure.
package net.ensode.jasperbook;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.export.JRHtmlExporter;
import net.sf.jasperreports.engine.export.JRHtmlExporterParameter;
import net.sf.jasperreports.j2ee.servlets.ImageServlet;
public class HtmlReportServlet2 extends HttpServlet
{
public static final String REPORT_DIRECTORY = "/reports";
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
Connection connection;
String reportName = request.getParameter("reportName");
 
Search WWH ::




Custom Search