Servlets

Code below shows using the DynamicReports within a servlet. The servlet will display a pdf document on the web browser.

import static net.sf.dynamicreports.report.builder.DynamicReports.*;
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.dynamicreports.report.exception.DRException;
public class PdfReportServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("application/pdf");
    OutputStream out = resp.getOutputStream();
    try {
      report()
        ...
        .toPdf(out);
    } catch (DRException e) {
      throw new ServletException(e);
    } 
    out.close();
  }
}
 

Latest News

  • Thu
    Jul
    28
    Changes in version 4.1.1 upgrade to JasperReports 6.2.2 added new types of component stretch type minor bug fixes...
  • Thu
    Feb
    11
    Changes in version 4.1.0 upgrade to JasperReports 6.2.0 xyList component, see ComponentsReport for an example
  • Wed
    Nov
    18
    Changes in version 4.0.2 upgrade to JasperReports 6.1.1 added support for QR Code barcode, see BarcodeReport for a...