示例 1 - 设置参数

下例是一个 JSP 页面,它演示了如何为包含 Country 参数的报表设置参数字段。设置了参数后,即会显示报表。

注意:    对于与本教程示例一起使用的任何报表,您必须配置了适当的 JDBC 数据源,以便应用程序服务器能访问它。本例中使用的报表未随附于教程中。

ParameterFieldsViewReport.jsp

<%@ page import="com.crystaldecisions.report.web.viewer.*" %>

<%@ page import="com.crystaldecisions.sdk.occa.report.data.*"  %>

<%@ page import="com.crystaldecisions.reports.sdk.ReportClientDocument" %>

<%

    Object reportSource = session.getAttribute("reportSource");

    if (reportSource == null)

    {

       String report = "/reports/sample.rpt";

       ReportClientDocument reportClientDoc = new ReportClientDocument();

       reportClientDoc.open(report, 0);

       reportSource = reportClientDoc.getReportSource();

       session.setAttribute("reportSource", reportSource);

    }

    Fields fields = new Fields();

    ParameterField pfield1 = new ParameterField();

    Values vals1 = new Values();

    ParameterFieldDiscreteValue pfieldDV1 = new ParameterFieldDiscreteValue();

    pfield1.setName("Country");

    pfield1.setReportName("");

    pfieldDV1.setValue("Spain");

    pfieldDV1.setDescription("The country is Spain.");

    vals1.add(pfieldDV1);

    pfield1.setCurrentValues(vals1);

    fields.add(pfield1);

    CrystalReportViewer viewer = new CrystalReportViewer();

    viewer.setReportSource(reportSource);

    viewer.setParameterFields(fields);

    viewer.setEnableParameterPrompt(false);

    if (session.getAttribute("refreshed") == null)

    {

viewer.refresh();

session.setAttribute("refreshed", "true");

    }

    viewer.setOwnPage(true);

    viewer.processHttpRequest(request, response, getServletConfig().getServletContext(), null);

%>



Business Objects
http://www.china.businessobjects.com/

支持服务
http://www.china.businessobjects.com/services/services.htm