Make (PDF) Report using iReport & Java (2)

After successfully make a template report (*.jrxml & *.jasper) using iReport tools, the next step is to ‘call’ the *.jasper file so it can be printed by a web application page using Java (JSP). These are the steps that we need to do  (according to the author experiences).

  1. Prepare these libraries, usually it’s already available on ‘lib’ directory in iReport installation folder.
    • commons-beanutils-1.7.jar
    • commons-collections-2.1.jar
    • commons-digester-1.7.jar
    • iReport.jar
    • itext-1.3.1.jar
    • jasperreports-3.0.0.jar
    • jstl.jar
    • mysql-connector-java-3.1.11-bin.jar
    • poi-3.0.1-FINAL-20070705.jar
    • standard.jar
    • xalan.jar

    Then, we have to copy those files to ‘lib’ directory on ‘WEB-INF’ in a web project. Below the screenshoot of Eclipse IDE.


  2. Now, we can create a simple JSP file, as example, we name it as ‘employeereport.jsp’ :
    • Import package/class
      <%@ page import="*, java.util.*, net.sf.jasperreports.engine.*, net.sf.jasperreports.engine.export.*" %>
    • Define the taglib
      <%@ page pageEncoding="UTF-8" %>
      <%@ taglib uri="" prefix="c" %>
      <%@ taglib uri="" prefix="c-rt" %>
      <%@ taglib uri="" prefix="fmt" %>
      <%@ taglib uri="" prefix="fmt-rt" %>
    • Type these code/scriptlet
      Map parameters = null;
      JRExporter jrExporter = null;
      //locate the file & its path *.jasper in this example is ‘BasicFeatures.jasper’
      JasperPrint jasperPrint =
      application.getRealPath("/hrdapp/report/jasper/BasicFeatures.jasper"), parameters, new JREmptyDataSource());OutputStream outputStream = response.getOutputStream();
      jrExporter = new JRPdfExporter();
      jrExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
      jrExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
  3. And now, we can access on localhost and we can get a PDF file outputPDF Report

Download Docs File (Bahasa Indonesia)