您必须先获得一个报表源,然后才能在 JSP 页面中使用导出控件或查看器。
报表源是一个对象,它代表着由导出控件和查看器使用的报表的单一实例。可以使用 Java Reporting Component、页面服务器和 RAS 来获得报表源。
要使用 Java Reporting Component 来创建报表源,您必须掌握要查看或导出的报表所在的位置。通过使用相对或绝对路径指定报表位置。而且,为使 Java Reporting Component 正确地为报表检索数据,必须通过 JNDI 正确指定报表的数据源,或必须依据 JDBC 数据源设计报表。
通过 Java Reporting Component 来获取报表源的方法有两种。 第一种(推荐的)方法是使用 ReportClientDocument 类获取报表源。 第二种方法是使用 IReportSourceFactory2 类。
import com.crystaldecisions.reports.sdk.ReportClientDocument;
ReportClientDocument reportClientDoc = new ReportClientDocument();
String report = "/reports/sample.rpt";
reportClientDoc.open(report, 0);
Object reportSource = reportClientDoc.getReportSource();
注意: 以上代码中的报表位置会有所不同,具体情况取决于您是使用相对还是绝对路径。 当使用相对路径时,以上报表会解析到 <web_app_dir>/WEB
session.setAttribute("reportSource", reportSource);
<%@ page import="com.crystaldecisions.reports.reportengineinterface.JPEReportSourceFactory" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.reportsource.IReportSourceFactory2" %>
IReportSourceFactory2 rptSrcFactory = new JPEReportSourceFactory();
注意: String report = "/reports/sample.rpt";
注意: Object reportSource = rptSrcFactory.createReportSource(report, request.getLocale());
注意: 取决于您是使用相对还是绝对路径,以上代码中的报表位置会不同。当使用相对路径时,以上报表会解析到 <web_app_dir>/WEB
。当使用绝对路径时,以上报表会先解析到 <web_app_dir>/WEB
,然后再解析到 /reports/sample.rpt
。
session.setAttribute("reportSource", reportSource);
Business Objects http://www.china.businessobjects.com/ 支持服务 http://www.china.businessobjects.com/services/services.htm |