最近为客户开发一个mis系统,java技术,b/s结构.客户要求系统的报表采用水晶报表.
怎样在jsp中实现水晶报表呢?找遍了所有的资料,水晶报表的web实现倒是很多,但都讲的是微软的.net方案.jsp中如何实现水晶报表的动态显示呢?
经过一段时间的痛苦摸索,现在把我的方案介绍给大家,希望各位大哥批评指正我的问题:
需要动态的显示水晶报表,并且要根据我传递的一个参数(BH)的值动态的显示数据.并且要可以把水晶报表导出为word,excel,pdf等格式
我的解决方案:
一:下载 crystal reports 10 for BEA weblogic workshop
二:安装crystal reports 10 for BEA weblogic workshop;
三:如果安装成功,则在C:\Program Files\Common Files\Crystal Decisions\2.5\bin目录下,可以找到CRDB_JavaServer.ini文件.该文件很重要,里面的内容
关系到水晶报表如何访问数据库.我的水晶报表采用jdbc的方式访问oracle数据库,配置如下:
[Common]
PATH = C:\bea\jdk141_05\bin
CLASSPATH = C:\Projects\Drivers\jdbc\classes12.jar;
C:\Projects\Drivers\jdbc\msbase.jar;
C:\Projects\Drivers\jdbc\mssqlserver.jar;
C:\Projects\Drivers\jdbc\msutil.jar;
C:\Projects\Drivers\jdbc\common.jar;
C:\Projects\Drivers\jdbc\db2fs.jar;
C:\Projects\Drivers\jdbc\db2java.zip;
C:\Projects\Drivers\jdbc\db2jcc.jar;
C:\Projects\Drivers\jdbc\weblogic.jar;
D:/Progra~1/IBM/WebSph~1/Applic~1\v5.1.1\runtimes\base_v51\lib\naming.jar;
D:/Progra~1/IBM/WebSph~1/Applic~1\v5.1.1\runtimes\base_v51\lib\namingclient.jar;
D:/Progra~1/IBM/WebSph~1/Applic~1\v5.1.1\runtimes\base_v51\lib\namingserver.jar;
D:/Progra~1/IBM/WebSph~1/Applic~1\v5.1.1\runtimes\base_v51\lib\cmImpl.jar;
D:/Progra~1/IBM/WebSph~1/Applic~1\v5.1.1\runtimes\base_v51\lib\j2cImpl.jar;
C:/projects/drivers/jdbc/weblogic.jar;
C:\Program Files\Common Files\Crystal Decisions\2.5\bin\CRDBJavaServer.jar;
C:\bea\weblogic81\server\lib\ojdbc14.jar
IORFileLocation = ${TEMP}
JavaServerTimeout = 1800
JVMMaxHeap = 64000000
JVMMinHeap = 32000000
[CRDB_JDBC]
CacheRowSetSize = 100
JDBCURL = jdbc:oracle:thin:@192.168.1.99:1521:pwsc
JNDIURL =
JDBCUserName = testuser
JDBCDriverName = oracle.jdbc.driver.OracleDriver
JNDIUserName = weblogic
JNDIConnectionFactory =
JNDIInitContext = /
GenericJDBCDriverBehavior = DB2
[CRDB_XML]
PREREADNBYTE = 5000
CacheRowSetSize = 100
XMLLOCALURL =
SCHEMALOCALURL =
XMLHTTPURL =
SCHEMAHTTPURL =
USETEMPFile = TRUE
以上是配置文件,需要说明的是:
1:由于我采用的是jdbc的方式访问数据库,所以CLASSPATH中一定要把C:\bea\weblogic81\server\lib\ojdbc14.jar加进去,它是jdbc的驱动
2:[CRDB_JDBC]中的:JDBCURL = jdbc:oracle:thin:@192.168.1.99:1521:pwsc 是我要访问的数据库名称.JDBCUserName = testuser是设置用户名,
JDBCDriverName = oracle.jdbc.driver.OracleDriver是jdbc驱动名称
四:在水晶报表编辑器中编辑我要用的报表.由于我需要动态的给报表传递参数,所以我在报表中设置了一个参数字段,水晶报表根据这个参数字段,就可以显示相应的
数据,参数字段命名为BH,在公式编辑器中编写如下代码:
IF {?BH}<>"" THEN
{GG_BPBJ.JLBH}={?BH}
ELSE
{GG_BPBJ.JLBH}="1" OR {GG_BPBJ.JLBH}<>"1"
以上代码的意思是:如果bh参数不为空,则显示{GG_BPBJ.JLBH}等于参数BH的记录,否则显示出所有的记录
(大家可能觉得{GG_BPBJ.JLBH}="1" OR {GG_BPBJ.JLBH}<>"1"很可笑,是啊,我开始是写成"true"了,在水晶报表编辑器中可以很好的运行,但方到web上显示就有
问题,万般无奈,只有如此了,:( )
五:在weblogic workshop中新建一个web项目,用右键选择该项目文件夹,选择"新建",选择"crystal report",则在该web项目根目录下自动新建了一个
crystalreportviewers10目录,里面有显示水晶报表需要的页面元素系统自动添加了开发水晶报表需要的jar包,共有13个jar文件(位于WEB_INF\LIB目录下),
并增加了一些水晶报表专用的标签(在WEB_INF\SRC下)
六:需要特别注意的是:在WEB_INF下的web.xml文件也随之改动,改动后的web.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<!-- The web.xml file is a configuration file used to control the behavior of WebLogic server.
In most cases, you will not need to modify this file. For more information on web.xml, please
consult the Web.xml Deployment Descriptor Elements chapter of the "Developing WebLogic Server
Applications" documentation on edocs.bea.com. -->
<web-app>
<display-name>Workshop Application</display-name>
<context-param>
<param-name>weblogic.httpd.inputCharset./*</param-name>
<param-value>GBK</param-value>
</context-param>
<context-param>
<param-name>crystal_image_uri</param-name>
<param-value>/webmis/crystalreportviewers10</param-value>
</context-param>
<filter>
<filter-name>PageFlowJspFilter</filter-name>
<filter-class>com.bea.wlw.netui.pageflow.PageFlowJspFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PageFlowJspFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<listener>
<listener-class>com.bea.wlw.runtime.core.servlet.WebappContextListener</listener-class>
</listener>
<!-- Standard Action Servlet Configuration (with debugging) -->
<servlet>
<servlet-name>messageServlet</servlet-name>
<servlet-class>com.infoearth.servlets.getTaskServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>com.bea.wlw.netui.pageflow.DynamicSubappActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/jpf-struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>config/-global</param-name>
<param-value>/WEB-INF/jpf-struts-config--global.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>drawImage</servlet-name>
<servlet-class>com.infoearth.drawimage.DrawImageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>drawImage</servlet-name>
<url-pattern>drawImage</url-pattern>
</servlet-mapping>
<!-- Struts Action Servlet Mappings -->
<!-- Note that because Struts takes the *last* mapping here as the extension to add to
actions posted from forms, we must have *.do come after *.jpf. -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.jpf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>messageServlet</servlet-name>
<url-pattern>/messageServlet</url-pattern>
</ser