IBM®
跳转到主要内容
    中国 [选择]    使用条款
 
 
Select a scope: Search for:    
    首页    产品    服务与解决方案     支持与下载    个性化服务    
跳转到主要内容

developerWorks 中国  >  Rational  >

使用 Rational Application Developer 在 Web 应用程序中集成水晶报表 (Crystal Reports),第 3 部分: 如何通过编程的方式使用 Java Reporting Component 代码在 Java Server Pages 中嵌入预设定的水晶报表 (Crystal Reports)

在 IBM Rational Application Developer 中使用 Embedded Crystal Reports Designer 工具的详细操作指南

developerWorks
文档选项

未显示需要 JavaScript 的文档选项

讨论

样例代码


级别: 中级

Robin Bajaj (robinbajaj@gmail.com), 高级程序设计与分析师, Rogers Communications Inc.

2007 年 8 月 27 日

这篇文章是这个系列文章的第三篇,将会给出一些使用 IBM Rational Application Developer 工具在 Web 应用程序中嵌入水晶报表 (Crystal Reports) 的经验。在这个系列文章的第一篇和第二篇中,您已经学到了如何为设计水晶报表 (Crystal Reports) 而设置您的软件,然后使用 Embedded Crystal Reports Designer 设计水晶报表 (Crystal Reports) 范例。然后通过将从 Report Page Viewer 组件从 Crystal Reports JSP Tags 拖拽到 Palette 视图中,从而将这些报告嵌入到 JavaServer Pages 技术(JSPs)中。这篇文章介绍了另外一种实现方法,以及使用 Java Reporting Component 更加强大的嵌入方法,同时还提供了额外的特性,例如为您的数据库存储程序设置参数,传递数据库登录识别符,以及打印或者导出报告。如果您的水晶报表 (Crystal Reports) 不仅仅是基本报告,那么您就需要这些高级特性,这篇文章将会对您有所帮助。

开发场景示例

在这篇文章中,您将会:

  1. 设置 CRDB_JavaServer.ini 文件
  2. 使用 JavaServer Pages ™ 技术(JSP)建立一个包含水晶报表的新 Web 项目
  3. 使用 Java™ Reporting Component (JRC) 有计划的将水晶报表嵌入到 JSP 中,然后在服务器上运行它

您在这里回顾的例子是基于 IBM® Rational® Application Developer Version 6.0.1.1,包含默认的 Crystal Reports Version XI 特性。大部分的读者使用过 IBM® WebSphere® Version 6 测试环境,包括 Rational Application Developer 试用版本的用户。因此,这篇文章的 Web 应用程序的例子,是设置在 WebSphere V6.0.2.5 测试环境下的,而不是 V5.1 测试环境。同时还需要使用 IBM® DB2® Universal Database Version 8.1,它包含一些这篇教程中用来产生报告的样本数据库。

想要了解更多基于水晶报表的用例的信息,请查看 Rational Application Developer Help 内容(Help > Help Contents > Developing Web Applications > Crystal Reports > Creating Reports)。想要下载这些产品的试用版本,请访问资源部分的 IBM 试用版本软件。您可以点击 Crystal Reports FAQs 链接到 Rational Application Developer Support 页面(查看资源),您会找到关于许可证,更新,或者其它关于 在 Rational Application Developer 中使用水晶报表工具的信息。





回页首


第一步,设置 CRDB_JavaServer.ini

这和同系列文章中的第 1 部分的第一步相同。如果您已经阅读过第 1 部分,并且已经设置好运行环境,那么您可以直接跳到第二步。否则,按照下列步骤设置您的文件:

  1. 在 Rational Application Developer 工作环境下,选择 Data 视图(Window > Open Perspective > Data)。
  2. 右键点击 Database Explorer 视图,然后选择 New Connection
  3. 选择选择一个 Database Manager 和 JDBC Driver(查看图1)。

图1:新建数据库连接对话框
Figure 1. Shows the New Database Connection dialog

  1. 点击Next按钮。
  2. New Database Connection 对话框中,输入图2所示的值,然后点击 Test Connection

图2:指定连接参数对话框
Figure 2. Screen capture of the specify connection parameters dialog

  1. 如果测试连接成功,点击 OK (如图3所示)。

图3:测试连接工作
Figure 3. Display shows that the test connection works

如果您遇到任何关于 Java™ Database Connectivity API (JDBC™) 连接的问题,那么请查找下列帮助信息:

  • 查阅您的数据库产品文档。
  • 查看 资源部分的 DB2 Infocenter 连接。
  • 查看您是否可以通过运行一个 Java™ 程序,从命令行测试 JDBC 的连接性(查看资源部分的 JDBC Test,它可以帮助您解决大多数厂商的大多数数据库的 JDBC 连接性问题。),而不使用 Rational Application Developer Data 视图连接到您的数据库。
  • 查看参考资源部分的 Business Objects' Supported Platforms,检查Business Objects 是否支持您的开发平台(数据库,操作系统等等)。

注释:参考资源部分的 Rational Application Developer 支持页面提到 IBM® z/OS® 和 IBM® iSeries™ 平台不支持使用 Business Objects 的水晶报表。但是,您还会找到在这些限制平台上工作的支持方法。

  1. 保持 New Database Connection 向导是打开状态,然后从C:\Program Files\Common Files\Crystal Decisions\2.5\bin\CRDB_JavaServer.ini打开 CRDB_JavaServer.ini 文件。
  2. 改变 CRDB_JavaServer.ini 文件中的值(如图4所示):
  • PATH指向包含 java.exe 文件的目录(最好在 jdk1.4.2 安装位置,例如 c:\program files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\bin)。
  • CLASSPATH从 New Database Connection 向导拷贝 Class Location,然后将其附加到已经存在的 CLASSPATH 中。如果您的类路径中存在空间(例如 Program Files),包含每一个引号中的 .jar 文件的 Class Location(例如:"c:\program files\IBM\SQLLIB\java\db2jcc.jar")。
  • IORFileLocation在您的文件系统上为所有临时文件夹提供一个有资格的路径。(您需要拥有 READ/WRITE 权限。)
  • JDBCURL从 New Database Connection 向导拷贝 Connection URL 值,然后将其替换现有的值。
  • JDBCUserName输入 db2admin 或者 您的数据库用户名。您可以稍后在 JDBC (Java™ Naming 和 Directory Interface,或者 JNDI) Connection Information 向导中更改它(查看图12)。
  • JDBCDriverName从 New Database Connection 向导拷贝 JDBC 驱动类,然后将其替换现有的值。

图4:拥有 JDBC 连接设置的 CRDBJavaServer.ini 文件
Figure 4. Shows the CRDBJavaServer.ini file, JDBC settings

注释:使用 Microsoft® Windows® Notepad 比其他文本编辑器要好,因为其他文本编辑器可以插入不可见的格式符号,它们可能会引起如图11所示的错误,甚至影响到相关参数的准确数值。

  1. 保存 CRDB_JavaSever.ini 文件,然后点击 New Database Connection 中的 Cancel 按钮。




回页首


第二步:使用 JSP 建立一个包含水晶报表的新 Web 项目

这个步骤和第 1 部分的第二步类似,有所不同的是这里的样本 Web 项目使用了 WebSphere V6.0 测试环境,而不是 V 5.1。在稍后的第四步中,您会再次使用这个步骤(第二步)的第五个子步骤,来使用 JNDI 运行您的报告。现在将其设置为在设计和运行时都使用 JDBC。

建立一个新的 Web 项目,按照下列步骤操作:

  1. 在您的 Rational Application Developer 平台上,选择 File > New > Dynamic Web Project,建立一个新的动态 Web 项目。
  2. 选择如图5所示的设置。

注释:在这个例子中,请确保您选择了2.4作为 servlet 版本,以及WebSphere Application Server V6.0 作为Target Server,如图5所示:


图5:New Dynamic Web Project 对话框
Figure 5. New Dynamic Web Project dialog display

  1. 点击 Next 按钮,然后选择 Features 对话框中的 Crystal Reports 特性,如图6所示:

图6:Web Project Features 对话框
Figure 6. Shows the Web Project Features dialog

  1. 点击 Finish 按钮。
  2. 在您的 Web 项目中,右键点击 WebContent 文件夹,然后选择 New > Crystal Report
  3. 选择 >New Crystal Report Wizard 中,如图7所示的设置:

图7:New Crystal Report 向导
Figure 7. Screen capture of the New Crystal Report Wizard

  1. 点击 Finish 按钮。
  2. 在 Crystal Reports Gallery 对话框中,选择 Report Wizard 选项(如图8所示):

图8:Crystal Reports Gallery 对话框
Figure 8. Shows the Crystal Reports Gallery dialog box

  1. 点击 OK 按钮。
  2. 在 Standard Report Creation Wizard 对话框中,点击 Create New Connection > JDBC (JNDI)(如图9所示):

图9:Standard Report Creation 向导
Figure 9. Shows the Standard Report Creation Wizard

  1. 如果您在 CRDB_JavaServer.ini 文件中的配置正确,那么 JDBC (JNDI) Connection 设置对话框(如图10所示)将会显示。Connection URLDatabase Classname 将会被来自 CRDB_JavaServer.ini 文件的正确的数值填充。
  2. 点击 Next 按钮。

图10:JDBC (JNDI) Connection 设置对话框
Figure 10. Shows the JDBC (JNDI) Connection settings dialog

注释:如果您没有看到 JDBC (JNDI) Connection 设置对话框,而是得到了如 图11所示的错误信息,那么请查看资源部分的 Resolve Java Server 启动失败错误


图11:JDBC (JNDI) Connection 设置对话框错误信息
Figure 11. JDBC (JNDI) Connection settings dialog box showing error

注释:如果向获得更多关于设置您的 CRDB_JavaServer.ini 文件的详细信息,请查看资源部分的 CRDB_JavaServer.ini 设置向导。

  1. 下一步,在 Connection Information 中输入您的 DB2 用户 ID密码(如图12所示):

图12:Connection Information 对话框
Figure 12. Shows the Connection Information dialog box

注释:这个对话框会收集您在 CRDB_JavaServer.ini 文件中提供的用户名。(查看图4)。如果您愿意,您可以在这里将其更换为任何数据库用户名。

  1. 点击 Finish 按钮。
  2. 图13所示的对话框中,在可用的表格中选择您想要产生报告的表格。例如,选择 Department 表格。

图13:Data 对话框
Figure 13. Shows the Data dialog box

  1. 点击 Next 按钮。
  2. Fields 对话框中(图14),从表格中选择您想要将表格显示的区域。

图14:Fields 对话框
Figure 14. Shows the Fields dialog box

  1. 点击 Next 按钮。
  2. 在 Grouping 对话框中(图15),选择您的分组选项(在这里我们使用默认值)。

图15:Grouping 对话框
Figure 15. Shows the Grouping dialog box

  1. 点击 Next 按钮。
  2. 在 Record Selection 对话框中(图16),选择您的记录选择优先级(在这里我们使用默认值)。

图16:Record Selection 对话框
Figure 16. Shows the Record Selection dialog

  1. 点击 Next 按钮。
  2. 在 Report Style 对话框图17),选择您的报告样式优先级(在这里我们使用默认值)。

图17:Report Style 对话框
Figure 17. Shows the Report Style dialog

  1. 点击 Finish 按钮,然后保存您对报告文件的更改(选择 File > Save)。




回页首


第三步:使用 JRC 代码有计划的将水晶报表嵌入到 JSP 中,然后在服务器上运行它

  1. 点击 BusinessObjects 支持站点Crystal Reports XI Java Reporting Component 的样板应用程序连接,下载这篇文章所用的启动样板代码。将下载的压缩文件解压缩到 c:\crxi_jrc_jsp_samples 路径下。
  2. 从 c:\crxi_jrc_jsp_samples\jrc_begin_here 文件夹,导入两个文件到您的 Web 项目的 WebContent 文件夹。
    • jrc_begin_here.jsp:这个文件包含安装信息和使用您的 Crystal Report 文件初始化 JRC (Java Reporting Component)对象。
    • CrystalReportViewer.jsp:这个文件包含阅读器代码,它用来将报告交付到 Web 页面。
  3. 现在编辑 jrc_begin_here.jsp 文件,让其为 您在第二步建立的 Crystal Report (Untitled.rpt)工作。
  1. 改变 reportName 变量值,使其指向您的 Crystal Report。由于您在 WebContent 文件夹中建立了 Untitled.rpt 文件,所以 reportName 的值应该是 Untitled.rpt,如代码列表1所示:

列表1:报告名称变量的值
                
String reportName = "Untitled.rpt";
			

  1. 来自 jrc_begin_here.jsp 文件的代码片段列表2中,使用 BusinessObjects' Java Reporting Component API 建立了一个 oReportClientDocument 对象,然后将其指向了您的 Untitled.rpt 文件。

列表2:建立 oReportClientDocument 对象的列表
                
//---------- Create a ReportClientDocument -------------
ReportClientDocument oReportClientDocument = 
new ReportClientDocument();
//---------- Set the path to the location of the report soruce 
------------- //Open report.
oReportClientDocument.open(reportName, 0); 

  1. 在代码片段列表3中,一个 reportSource 对象被包含在 oReportClientDocument 对象中,然后将其放入会话区域。

列表3:找回 reportSource 对象的代码
                
//Get the report source and put it into session scope
reportSource = oReportClientDocument.getReportSource();
session.setAttribute("reportSource", reportSource);  
			

  1. 然后,代码片段列表4显示了将浏览器找回 CrystalReportViewer.jsp 文件。

列表4:将浏览器找回 Crystal Report Viewer JSP 的代码
                
response.sendRedirect("CrystalReportViewer.jsp");
			

列表5显示了变更的 jrc_begin_here.jsp 文件的内容。想要下载完整版本的代码,请下载资源部分的 SampleWebApplication.zip 文件,并找到 jrc_begin_here.jsp 文件。


列表5:变更的 jrc_begin_here.jsp 文件的内容
                
//Use the relative path to the report; the physical or full qualified 
URL cannot // be used.
String reportName = "Untitled.rpt";
try
{
    //check to see if the report source already exists
    Object reportSource = session.getAttribute("reportSource");
    //if the report source has not been opened
    if (reportSource == null)
    {
        //---------- Create a ReportClientDocument -------------
        ReportClientDocument oReportClientDocument = 
        new ReportClientDocument();

        //---------- Set the path to the location of the report soruce 
        -------------

        //Open report.
        oReportClientDocument.open(reportName, 0);

        //Get the report source
        reportSource = 
        oReportClientDocument.getReportSource();

        //Cache report source.  
        //This will be used by the viewer to display the 
        desired report.
        session.setAttribute("reportSource", reportSource);
    }
    response.sendRedirect("CrystalReportViewer.jsp");
}
catch(ReportSDKException e)
{
    out.print(e);
}    

理解 Crystal Report Viewer JSP 代码

现在,让我们考虑一下 CrystalReportViewer.jsp 代码。

列表6的代码片段显示了下列这些功能:

  • 从会话中找回 reportSource
  • 示例 CrystalReportViewer 如何建立 oCrystalReportViewer 对象
  • 设置 oCrystalReportViewer 的报告资源为从会话中找回的 reportSource 对象

列表6:CrystalReportViewer.jsp 代码
                
//Get the IReportSource object from session and pass it to the viewer
IReportSource reportSource = (IReportSource)session.getAttribute
("reportSource");

//---------- Create the viewer and render the report -------------

//create the CrystalReportViewer object
CrystalReportViewer oCrystalReportViewer = 
new CrystalReportViewer();
//set the reportsource property of the viewer
oCrystalReportViewer.setReportSource(reportSource);
			

下列三段代码片段设置了阅读器属性(oCrystalReportViewer 对象):

  • 列表7设置阅读器是否控制自己的页面。设置属性 setOwnPage 为 true,即可同过允许阅读器完全控制相关 HTML 内容而获得很多好处。这就降低了您需要添加到 JSP 中的代码数量,并且允许阅读器自动决定可靠的设置。

列表7:设置阅读器为可以处理相关 HTML 内容
                
oCrystalReportViewer.setOwnPage(true);
			

  • 列表8的代码片段设置了阅读器是否可以控制自己的形式。如果服务其控制自己的形式,那么我们就可以获得并且设置形式的值。特别是我们拥有形式后,阅读器控制可以将状态信息缓冲到客户端。

列表8:设置阅读器是否可以控制自己的形式
                
oCrystalReportViewer.setOwnForm(true);
			

  • 列表9中的代码片断设置了时候可以使用 PDF 或者 ActiveX 格式打印。PDF 打印格式中,一个 PDF 将会被显示,允许用户打印它。在 ActiveX 打印模式中,一个小的 ActiveX 控件将会被下载到客户端机器上,以执行打印工作。如果用户在一个不支持 ActiveX 打印模式的机器上选择了 ActiveX 打印,那么将会以默认的 PDF 模式打印客户的请求。

列表9:设置是否可以使用 PDF 或者 ActiveX 打印模式
                
oCrystalReportViewer.setPrintMode(CrPrintMode.PDF); 
// the other print mode is CrPrintMode.ACTIVEX
			

注释:

  • 想要了解更多关于刚才提到的属性,以及其他可用的 CrystalReportViewer 属性的信息,您可以从 Help > Help Contents > Developing Web Applications > Crystal Reports > API Reference > Viewer Java Classes > Crystal Report Viewer 访问 Rational Application Developer Help。
  • 如果您在打印或者导出水晶报表阶段遇到了任何问题,特别是列表10所示的异常,您可以查看资源部分的 WebSphere 服务器在执行导出或者打印水晶报表时抛出运行时错误如何解决正在打印或者导出水晶报表时发生的运行时错误来寻求解决方案。

列表10:您可能在打印或者导出水晶报表时遇到的异常
                
java.lang.IllegalStateException: SRVE0199E: 
OutputStream already obtained
			

  • 第三个代码片段,如列表11所示,处理并交付报告到 Web 页面。

列表11:列出最大宽度的样板代码
                
oCrystalReportViewer.processHttpRequest(request, response,
getServletConfig().getServletContext(), null);
			

在 IBM® WebSphere® 服务器上运行页面:

  1. 右键点击 Project Explorer 视图中的 jrc_begin_here.jsp,然后选择 Run > Run on Server 查看包含 Crystal Report 的 JSP。(查看图18。)

图18:在浏览器中浏览包含 Crystal Report 的 JSP
Figure 18. Shows the Database Login page

注释:
如果您看到数据库登录界面(图19),那么请提供您的 IBM® DB2® 用户名和密码,然后点击 OK 按钮。


图19:数据库登录页面
Figure 19:  Shows the Database Login page

您可以使用下面任意一个替换方法来跳过这个数据库登录页面:

  • 查看这个系列文章中的第二篇的第四步,“使用 Rational Application Developer 在 Web 应用程序中集成水晶报表”(查看资源部分),建立一个报告在运行时切换到 JNDI。如果您将 jrc_begin_here.jsp 文件指到这个报告(如之前第四个子步骤),它会自动为您通过登录信令,因此您就不需要访问数据库登录页面。这个方法能够最好的允许您编写 JRC 代码并且通过允许使用基于 JNDI 技术的报告。这些报告自动为您处理认证。同时,JRC 是一个详细的 API,它能让您通过使用 Palette 视图而比使用Report Viewer Control 更好的控制报告。
  • 第二种替代方法是从jrc_begin_here.jsp 和 CrystalReportViewer.jsp 文件这两个代码片段中删除部分代码。列表12代码片段建立了一个 oConnectionInfos 对象,使用您的用户名和密码初始化了这个对象,然后将其设置在会话范围中。列表13代码片段从会话范围找回了 ConnectionInfos 对象,并且将其和 oCrystalReportViewer 对象关联起来,作为一个 DatabaseLogonInfos 属性值存在。

列表12:oConnectionInfos 对象的代码
                
//Database username and password
String userName = "devtech";
String password = "devtech";

//Create a new ConnectionInfos and ConnectionInfo object; 
the ConnectionInfo
//  will be added to the ConnectionInfos collection after the 
properties are //  set.  The collection can be a collection of one 
or more objects.
ConnectionInfos oConnectionInfos = new ConnectionInfos();
ConnectionInfo oConnectionInfo = new ConnectionInfo();

//Set username and password for the report's database
oConnectionInfo.setUserName(userName);
oConnectionInfo.setPassword(password);

//Add object to collection
oConnectionInfos.add(oConnectionInfo);

session.setAttribute("oConnectionInfos", oConnectionInfos);


列表13:将 ConnectionInfos 对象和 oCrystalReportViewer 对象作为一个 DatabaseLogonInfos 属性值关联起来
                
// retrieve the ConnectionInfos object from the session
ConnectionInfos connectionInfos =
(ConnectionInfos)session.getAttribute("oConnectionInfos");
//set the connectionInfos
oCrystalReportViewer.setDatabaseLogonInfos(connectionInfos);

注释:

  • 由于 jrc_begin_here.jsp 代码将浏览器重定向到了 CrystalReportViewer.jsp 文件,Web 站点用户通常不会在浏览器中查看 Web 页面源代码而看到您的数据库的用户名和密码。
  • 虽然您可以考虑这两种替换方法的任意一种,但是值得一提的是第一种替换方法,它建议在运行时使用报告来切换到 JNDI,这样更加安全,因为认证是由在 JNDI 数据源中设置的 Java™ Authentication 和 Authorization Service (JAAS) 模块自动完成的。除此之外,它还去除了 jrc_begin_here.jsp 文件中登录认证的需求代码。

如何处理运行期间发生的异常

这个过程运行期间可能会产生一些异常。下面是处理这些异常的一些方法:

  • 如果您在这个过程中遇到 JDBC Driver 运行时错误(图20),请从 <DB2-Install-directory>\SQLLIB\java 目录拷贝 DB2 Universal JDBC Driver .jar 文件(db2jcc.jar, db2jcc_license_cu.jar,和 db2jcc_license_cisuz.jar)到您的<WebSphere-Application-Serverv6.0.x-Install-directory>\lib\ext 目录。(注释:如果您使用的是 WebSphere V6.0 测试环境,而不是单机的 IBM® WebSphere® Application Server V6.0 ( <WebSphere-Application-Serverv6.0.x-Install-directory> = <RAD-install-directory>\runtimes\base_v6):在您拷贝完 .jar 文件后,右键点击服务器的 Servers 视图,选择Restart > Start重新启动服务器。

图20:JDBC Driver 运行时错误
Figure 20: Screen capture of the JDBC Driver runtime error

  • 如果您看到如列表14Console 视图所示的错误信息,请查看资源部分的:“如何解决 log4j 错误”。

列表14:将 ConnectionInfos 对象和 oCrystalReportViewer 对象作为一个 DatabaseLogonInfos 属性值关联起来的代码
                
[2/14/06 17:38:36:435 EST] 00000031 SystemErr
R log4j:ERROR setFile(null,true) call failed.
[2/14/06 17:38:36:435 EST] 00000031 SystemErr
R java.io.FileNotFoundException: 
C:\Documents and Settings\Administrator\crystal\jpe.log
(The system cannot find the path specified)
	at java.io.FileOutputStream.openAppend(Native Method)
	at java.io.FileOutputStream.init(FileOutputStream.java:199)
	at java.io.FileOutputStream.init(FileOutputStream.java:124)
	at org.apache.log4j.FileAppender.setFile(FileAppender.java:272)
	at org.apache.log4j.RollingFileAppender.setFile
	(RollingFileAppender.java:156)

如何限制使用 JRC 代码中的 scriptlets

有一件事情您可能在 jrc_begin_here.jsp 文件中已经注意到了,就是它的代码大多数使用了 JSP scriptlets。如果您想避免使用过多的 scriptlets,那么您可以使用 JRC API 中 BusinessObjects 提供的 taglibs。列表15所示的代码片段显示了上面使用 scriptlets 配置的所有属性信息,我们可以使用 <crviewer> 标签配置它。如果您想要获得完整的代码列表,请到资源部分下载 SampleWebApplication.zip 文件,然后查看其中的 jrc_begin_here_taglib.jsp 文件。


列表15:使用 <crviewer> 标签配置属性
                
<%@ taglib uri="/crystal-tags-reportviewer.tld" 
prefix="crviewer" %>
<html>
<body>

<!-- Create an opening viewer tag to specify the viewer name 
and the type of report source.
When using the Java Reporting Component, the reportSourceType 
will be "reportingComponent"
This viewer tag has several viewer properties set as well.
These can be set in the IDEs that come with JRC or manually.-->

<crviewer:viewer viewerName="CrystalViewer" 
		reportSourceType="reportingComponent"
		displayGroupTree="false"
        isOwnPage="true"
        displayToolbarExportButton="true"
        displayToolbarPrintButton="true"
        displayToolbarRefreshButton="true"
        displayToolbarToggleTreeButton="false"
        displayToolbarCrystalLogo="true">

<!-- Create the required report tag to specify the report to display 
and the session variable to cache the report source. -->
<crviewer:report reportName="Untitled.rpt"/>
</crviewer:viewer>
</body>
</html>

  • 如果您在运行 jrc_begin_here_taglib.jsp 文件时,看到了列表16所示的错误信息,请确定您在列表15代码片段中为您的 Crystal Report (.rpt file)输入了正确的路径。

列表16:最大宽度的样板代码列表
                
com.crystaldecisions.sdk.occa.report.lib.ReportSDKException: 
Report file 
/C:/RSA_workspaces/dWArticle2_3/SampleWeb/WebContent/
jrc_view_tag_library_basic/jrc_view_tag_library_basic.rpt not found 
---- Error code:-2147467259 Error code name:failed
	at com.crystaldecisions.reports.reportengineinterface.
	JPEReportSource.a
	(Unknown Source)
	at com.crystaldecisions.reports.reportengineinterface.
	JPEReportSourceFactory.createReportSource
	(Unknown Source)
	at com.crystaldecisions.report.web.a.a.M(Unknown Source)
	at com.crystaldecisions.report.web.event.aa.a(Unknown Source)
	at com.crystaldecisions.report.web.event.aa.a(Unknown Source)
	at com.crystaldecisions.report.web.event.bx.a(Unknown Source)
	at com.crystaldecisions.report.web.event.b1.broadcast
	(Unknown Source)
	at com.crystaldecisions.report.web.event.as.a(Unknown Source)
	at com.crystaldecisions.report.web.WorkflowController.if
	(Unknown Source)
	at com.crystaldecisions.report.web.
	WorkflowController.doLifecycle
	(Unknown Source)
	at com.crystaldecisions.report.web.ServerControl.a
	(Unknown Source)





回页首


这个系列文章的下一篇会是什么

这是这个系列文章中的第三篇,它讲述了关于在 Web 应用程序中如何嵌入 Crystal Reports。在这篇文章中,您学到了一种更加强大的方法,就是使用 Report Page Viewer 控制来将报告嵌入到您的 JSP 技术中。现在,您可以在编写 Java Reporting Component 代码时,在 JSP 中指向预定的 Crystal Reports。由于 JRC 是一个更加强大的和详细的 API,它为您提供了很多控制您的报告运行行为的方法。

这个系列文章的第四篇将会讲述如何使用 JRC 的额外特性,例如,从运行时数据和使用 JRC 的 XML 数据导入。正如这篇文章中所提到的,使用 Embedded Crystal Report Designer 来制作设计时间的 JDBC 链接到 IBM z/OS 和 iSeries 平台是不被支持的。第四和第五篇文章将会帮助开发人员解决这方面的技术困难。






回页首


下载

描述名字大小下载方法
zip file containing EAR project and Readme.txtSampleWebApplication.zip3KBHTTP
关于下载方法的信息


参考资料

学习

获得产品和技术

讨论


关于作者

Robin 拥有位于萨科拉曼多(加州首府)的加利福尼亚州立大学的计算机科学硕士学位。他在写这篇文章时正在 IBM 多伦多实验室工作,担任 RAD 和 WSAD 工具的支持工程师。他现在担任多伦多一家主营电信业的公司(Rogers 通信公司)的高级程序设计与分析师。




对本文的评价










回页首


IBM 公司保留在 developerWorks 网站上发表的内容的著作权。未经IBM公司或原始作者的书面明确许可,请勿转载。如果您希望转载,请通过 提交转载请求表单 联系我们的编辑团队。
    关于 IBM 隐私条约 联系 IBM 使用条款