Lesson 4: Exporting a report from JSP

You have been asked to run EmployeeInformation.cls from the Sales Order application and allow the user to choose the format of the report. The allowable formats are: PDF, Excel, RTF (Microsoft Word), HTML, Text, PostScript, and XML.

In this lesson you again use Page Report Studio API to run the report; however, we will use the One Step Export feature to export the page report in the specified format without displaying it in a separate web browser window.

Task 1: Review the JSP file to run the report

The JSP page that runs the report is provided as part of the lesson. Follow these steps to review the JSP code:

  1. Copy exportReport.html in <install_root>\help\samples\JSPSamples\JinfonetGourmetJavaDemo to <install_root>\public_html\jag.
  2. Open exportReport.html in your favorite editor.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title>Export Report to user selected format</title>
    <script id="j$vm" type="text/javascript" src="../webos/jsvm/lib/jreportapi.js"></script>
    <script src="../webos/jsvm/lib/jquery-1.5.2.min.js"></script>
    <script language="JavaScript">
    (function(){
    var thi$ = self;
    var server = {
    url: "../jinfonet/tryView.jsp",
    user: "admin",
    pass: "admin",
    jrd_prefer:{
    // For page report
    pagestudio:{
    feature_UserInfoBar:false,
    feature_ToolBar: false,
    feature_Toolbox: false,
    feature_DSOTree: false,
    feature_TOCTree: false,
    feature_PopupMenu: false,
    feature_ADHOC: false
    },

    // For web report
    wrptstudio:{
    viewMode:{
    hasToolbar: false,
    hasSideArea: false
    }
    }
    },
    jrd_studio_mode: "view",
    "jrs.param_page": true
    },

    prptRes = {name:"/JinfonetGourmetJava/EmployeeInformation.cls"},
    catRes = {name:"/JinfonetGourmetJava/JinfonetGourmetJava.cat"},

    params = {
    };

    var Factory = com.jinfonet.api.AppFactory;
    var entryId="report1";

    thi$.openPageReport = function(){
    var app = Factory.runReport(
    server, prptRes, catRes, params, entryId);

    app.attachEvent("jreportstatus", 4, this, function(e){
    var msg = e.getData();

    });
    };


    thi$.guiExport = function(){
    var app = Factory.getApp(entryId), rptset;
    if(!app) return;

    rptset = app.getReportSet();
    rptset.exportTo();
    };

    })();

    </script>
    </head>
    <body >
    <input type="button" value="Open Report" onClick="openPageReport();">
    <input type="button" value="Export Report" onClick="guiExport();">
    <div id="report1" style="position:relative;height:640px;"></div>
    </body>
    </html>

    Note: The result types are: 0- HTML, 2 - PDF, 3 - Postscript, 4 - RTF, 5 - TEXT, 6 - Excel, 7 - XML.

Task 2: Export the report result

  1. Browse http://localhost:8888/jag/exportReport.html.
  2. Choose the desired export format and whether you want to download the result or view it now.
  3. Click Export to generate the exported report.

    The report displays according to the format provided. For downloaded result, use the program on your system to view the results, such as Acrobat Reader or Microsoft Word.

Lesson 4 summary

In this lesson you have learned how to use JSP and Page Report Studio API to run a report and export the current report tab in this report to any format.