Js|web| Crystal Report recently for customers to develop a MIS system, Java technology, B/s structure. The customer requests the system The report uses the Crystal Report.
How to realize the Crystal Report in JSP? Look through all the data, Crystal Report Web implementation is a lot, but all about Microsoft's. NET scenario. How to realize the dynamic display of Crystal Report in JSP?
After a period of painful groping, and now introduce my proposal to everyone, I hope that your eldest brother criticized
My question:
The Crystal report needs to be displayed dynamically, and the data will be displayed dynamically according to the value of one of the parameters (BH) I pass. And you can export the Crystal Report to word,excel,pdf format
My solution:
One: Download Crystal Reports for BEA WebLogic Workshop
Two: Install Crystal Reports for BEA WebLogic workshop;
Third: If the installation is successful, the Crdb_javaserver.ini file can be found in the C:\Program Files\Common Files\Crystal Decisions\2.5\bin directory. The file is important and the contents
Related to Crystal Reports how to access the database. My Crystal report accesses the Oracle database in a JDBC manner, configured as follows:
These are the configuration files that need to be described:
1: Because I am using the JDBC way to access the database, so classpath must add C:\bea\weblogic81\server\lib\ojdbc14.jar, it is JDBC driver
2:[CRDB_JDBC]: Jdbcurl = JDBC:ORACLE:THIN:@192.168.1.99:1521:PWSC is the name of the database I want to access. Jdbcusername = TestUser is to set the user name,
Jdbcdrivername = Oracle.jdbc.driver.OracleDriver is the JDBC driver name
IV: Edit the report I want to use in the Crystal Report editor. Because I need to dynamically pass parameters to the report, so I set a parameter field in the report, the Crystal Report according to this parameter number segment, you can display the corresponding
Data, the parameter field is named BH, and the following code is written in the formula editor:
IF {? Bh}<> "" THEN
{GG_BPBJ. Jlbh}={? BH}
ELSE
{GG_BPBJ. jlbh}= "1" OR {gg_bpbj.jlbh}<> "1"
The above code means that {GG_BPBJ is displayed if the BH parameter is not empty. JLBH} equals the record of the parameter BH, otherwise all records are displayed
(You may think {gg_bpbj.) jlbh}= "1" OR {gg_bpbj. Jlbh}<> "1" is ridiculous, yes, I began to write "true", in the Crystal Report editor can be very good to run, but side to the web display on the
Question, helpless, only so,:()
Five: Create a new Web project in WebLogic Workshop, right-click the project folder, select "New", select "Crystal", then automatically create a new one in the Web project root directory
CRYSTALREPORTVIEWERS10 directory, which has the page elements that show the Crystal report the system automatically adds the jar package needed to develop the Crystal Report, a total of 13 jar files (located in the Web_inf\lib directory),
and added some special labels for Crystal Reports (under WEB_INF\SRC)
VI: Special attention needs to be paid to the following changes in the Web.xml documents under Web_inf, Web.xml documents as follows:
<?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 the behavior of WebLogic server.
In most cases, you won't 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>
<!--Struts Action Servlet Mappings-->
<!--Note This because Struts takes the *last* mapping here as the extension to add to
The 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>
</servlet-mapping>
<mime-mapping>
<extension>doc</extension>
<mime-type>application/msword</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xls</extension>
<mime-type>application/msexcel</mime-type>
</mime-mapping>
<welcome-file-list>
<welcome-file>Login/loginController.jpf</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>
<!--Define the Netui tag library TLDs-->
<taglib>
<taglib-uri>netui-tags-html.tld</taglib-uri>
<taglib-location>/WEB-INF/netui-tags-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>netui-tags-databinding.tld</taglib-uri>
<taglib-location>/WEB-INF/netui-tags-databinding.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>netui-tags-template.tld</taglib-uri>
<taglib-location>/WEB-INF/netui-tags-template.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/crystal-tags-reportviewer.tld</taglib-uri>
<taglib-location>/WEB-INF/crystal-tags-reportviewer.tld</taglib-location>
</taglib>
</web-app>
which
<context-param>
<param-name>crystal_image_uri</param-name>
<param-value>/webmis/crystalreportviewers10</param-value>
</context-param>
Very key, it set the Crystal Report dedicated CRYSTALREPORTVIEWERS10 path (fifth step automatically built Crystalreportviewers10 directory), if set wrong, the future click on the Crystal Report from the
Export and print buttons will be reported page errors, and Crystal report their own various pages, export and other icons can not be displayed normally.
Seven: the editor of the Crystal Report (suffix rpt) placed in a directory (I built a report directory, dedicated to the reporting file)
Eight: Can write the program:
1. Write the Reportinit class. function: Used for passing parameters BH. This class is critical, and is responsible for passing Java parameter values to the Crystal Report file.
2. Increase the showrpt operation in the page flow: In fact, it is an instance of a Reportinit class.
3. Write viewer.jsp file for dynamic display of Crystal Report.
I have the source code behind, please criticize correct.
The problems that exist:
1: Crystal Report exported to PDF file problems: Chinese characters appear as garbled, somehow? This problem has been bothering me for months.
2: Unable to print/Export page in Chinese: In the CRYSTALREPORTVIEWERS10\JS directory has a series of strings named JS file, I guess is used to internationalize the page, but I modified
Strings_zh,js,strings_en.js, no effect.
3: After displaying the Crystal report in the browser, close the display page and the Crystal Report is still connected to the database (the number of Oracle connections can be viewed by the select * from V$session). If the
To join a disconnected statement in viewer.jsp:
Viewer.dispose ();
Rptsource.dispose ();
Only one page of the report can be displayed. and printing and exporting do not work.
The above problem has been bothering me for a long time, although it does not affect the use, but the heart is not very cool. Hope to master the guidance.
SOURCE program:
/*
* Create date:2004-8-14 11:06
* Create by: Li Chunlei
* Purpose: Set the Crystal Report query parameters (currently supports 7 parameters of the query, useful parameters are numbered)
*/
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.