Lesson 2: Calling a page report from JSP

This lesson assumes that you have been asked to integrate ProductSalesAnalysis.cls with a JSP page in the Sales Order application. However, you need more flexibility than the JReport mainpage tag provides. This lesson will display ProductSalesAnalysis.cls in Page Report Studio in a new web browser window.

In this lesson you will use Page Report Studio API to run the report instead of using the tag library. The JSP page that runs the report is provided as part of the lesson.

  1. Browse to and copy the runProductSalesAnalysis.jsp file in <install_root>\help\samples\JSPSamples\JinfonetGourmetJavaDemo to <install_root>\public_html\jag.

    Create the jag directory if you did not already do so in Lesson 1.

  2. Open runProductSalesAnalysis.jsp in your favorite editor or an editor that recognizes JSP such as Eclipse or Dreamweaver.
    <%@ page import="jet.web.dhtml.*" %>
    <%@ page import="java.util.*" %>
    <!-- include the jsp for check user login -->
    <%@ include file="../dhtmljsp/AuthCheck.jsp" %>
    <%
    Hashtable htparams = new Hashtable();
    //set report info
    htparams.put("jrs.cmd", "jrs.try_vw");
    htparams.put("jrs.result_type", "8");
    htparams.put("jrs.report ", "/USERFOLDERPATH/admJinfonetGourmetJavas/ProductSalesAnalysis.cls");
    htparams.put("jrs.catalog ", "/USERFOLDERPATH/admin/JinfonetGourmetJava/JinfonetGourmetJava.cat");

    Map tmpmap = DHTMLUtil.runReport(request, htparams);
    String targetURL = null;
    String errorMsg = null;

    if(tmpmap != null){
    errorMsg = (String)tmpmap.get(DHTMLConstant.ERROR_MSG);
    targetURL = (String)tmpmap.get(DHTMLConstant.TARGET_URI);
    if(errorMsg != null && !errorMsg.trim().equals("")){
    PrintWriter jwout = response.getWriter();
    jwout.print(errorMsg);
    return;
    }else{
    //forward to refresh jsp
    if(targetURL != null && !targetURL.trim().equals("")) {
    response.sendRedirect(targetURL);
    }
    }
    }
    %>
  3. Open your browser to http://localhost:8888/jag/runProductSalesAnalysis.jsp.

    The report is displayed according to the specifications provided.

Lesson 2 summary

In this lesson you have learned how to use JSP and Page Report Studio API to run a report.