|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
你希望java的IDE整合。这个是没有必要的,重要的是你理解java有多深以及怎么组织你的代码,即使没有IDE,代码照样能够编译运行的。js|水晶报表比来为客户开辟一个mis体系,java手艺,b/s布局.客户请求体系的报表接纳水晶报表.
如何在jsp中完成水晶报表呢?找遍了一切的材料,水晶报表的web完成却是良多,但都讲的是微软的.net计划.jsp中怎样完成水晶报表的静态显现呢?
经由一段工夫的疾苦探索,如今把我的计划先容给人人,但愿列位年老品评斧正我的成绩:
必要静态的显现水晶报表,而且要依据我传送的一个参数(BH)的值静态的显现数据.而且要能够把水晶报表导出为word,excel,pdf等格局
我的办理计划:
一:下载crystalreports10forBEAweblogicworkshop
二:安装crystalreports10forBEAweblogicworkshop;
三:假如安装乐成,则在C:ProgramFilesCommonFilesCrystalDecisions2.5in目次下,能够找到CRDB_JavaServer.ini文件.该文件很主要,内里的内容
干系到水晶报表怎样会见数据库.我的水晶报表接纳jdbc的体例会见oracle数据库,设置以下:
[Common]
PATH=C:eajdk141_05in
CLASSPATH=C:ProjectsDriversjdbcclasses12.jar;
C:ProjectsDriversjdbcmsbase.jar;
C:ProjectsDriversjdbcmssqlserver.jar;
C:ProjectsDriversjdbcmsutil.jar;
C:ProjectsDriversjdbccommon.jar;
C:ProjectsDriversjdbcdb2fs.jar;
C:ProjectsDriversjdbcdb2java.zip;
C:ProjectsDriversjdbcdb2jcc.jar;
C:ProjectsDriversjdbcweblogic.jar;
D:/Progra~1/IBM/WebSph~1/Applic~1v5.1.1untimesase_v51lib
aming.jar;
D:/Progra~1/IBM/WebSph~1/Applic~1v5.1.1untimesase_v51lib
amingclient.jar;
D:/Progra~1/IBM/WebSph~1/Applic~1v5.1.1untimesase_v51lib
amingserver.jar;
D:/Progra~1/IBM/WebSph~1/Applic~1v5.1.1untimesase_v51libcmImpl.jar;
D:/Progra~1/IBM/WebSph~1/Applic~1v5.1.1untimesase_v51libj2cImpl.jar;
C:/projects/drivers/jdbc/weblogic.jar;
C:ProgramFilesCommonFilesCrystalDecisions2.5inCRDBJavaServer.jar;
C:eaweblogic81serverlibojdbc14.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:eaweblogic81serverlibojdbc14.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上显现就有
成绩,万般无法,只要云云了,:()
五:在weblogicworkshop中新建一个web项目,用右键选择该项目文件夹,选择"新建",选择"crystalreport",则在该web项目根目次下主动新建了一个
crystalreportviewers10目次,内里有显现水晶报表必要的页面元素体系主动增加了开辟水晶报表必要的jar包,共有13个jar文件(位于WEB_INFLIB目次下),
并增添了一些水晶报表公用的标签(在WEB_INFSRC下)
六:必要出格注重的是:在WEB_INF下的web.xml文件也随之修改,修改后的web.xml文件以下:
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEweb-appPUBLIC"-//SunMicrosystems,Inc.//DTDWebApplication2.3//EN""http://java.sun.com/dtd/web-app_2_3.dtd">
<!--Theweb.xmlfileisaconfigurationfileusedtocontrolthebehaviorofWebLogicserver.
Inmostcases,youwillnotneedtomodifythisfile.Formoreinformationonweb.xml,please
consulttheWeb.xmlDeploymentDescriptorElementschapterofthe"DevelopingWebLogicServer
Applications"documentationonedocs.bea.com.-->
<web-app>
<display-name>WorkshopApplication</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>
<!--StandardActionServletConfiguration(withdebugging)-->
<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>
<!--StrutsActionServletMappings-->
<!--NotethatbecauseStrutstakesthe*last*mappinghereastheextensiontoaddto
actionspostedfromforms,wemusthave*.docomeafter*.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>
<!--DefinetheNetUItaglibraryTLDs-->
<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>
个中:
<context-param>
<param-name>crystal_image_uri</param-name>
<param-value>/webmis/crystalreportviewers10</param-value>
</context-param>
很关头,它设置了水晶报表公用的crystalreportviewers10路径(第五步中主动建的crystalreportviewers10目次),假如设置毛病,未来点击水晶报表自带的
导出和打印按钮是就会报页面毛病,而且水晶报表本人的各类翻页,导出等图标也没法一般显现.
七:把编纂好的水晶报表(后缀命为rpt)放在一个目次下(我本人建了一个report目次,专门寄存报表文件)
八:能够写程序了:
1.编写ReportInit类.感化:用于传送参数BH.这个类很关头,卖力把java的参数值传送到水晶报表文件.
2.在页面流中增添showRpt操纵:实在就是实例化一个ReportInit类.
3.编写viewer.jsp文件用来静态显现水晶报表.
前面有我的源代码,请人人品评斧正.
存在的成绩:
1:水晶报表导出成pdf文件时有成绩:汉字显现为乱码,不知何以?此成绩困扰我几个月了,没法办理
2:没法把打印/导出页面汉化:在crystalreportviewers10js目次下有一系列strings定名的js文件,我推测是用来国际化页面的,但是我修正
strings_zh,js,strings_en.js,没有甚么效果.
3:在扫瞄器中显现水晶报表后,封闭显现页面,该水晶报表仍然和数据库毗连,(可由select*fromv$session检察oracle的毗连数).假如在
viewer.jsp中到场断开毗连的语句:
viewer.dispose();
rptSource.dispose();
则只能显现一页报表.而且打印和导出不克不及事情.
以上成绩困扰我好久,固然其实不影响利用,但心中仍是不是很爽.但愿妙手指导.
源程序:
/*
*CreateDate:2004-8-1411:06
*CreateBy:李春雷
*purpose:设置水晶报表的查询参数(今朝撑持7个参数的查询,有效的参数为编号)
*/
packagecom.infoearth.report;
importcom.crystaldecisions.report.web.viewer.*;
importcom.crystaldecisions.sdk.occa.report.data.*;
importcom.crystaldecisions.reports.reportengineinterface.JPEReportSourceFactory;
importcom.crystaldecisions.sdk.occa.report.reportsource.IReportSourceFactory2;
importcom.crystaldecisions.sdk.occa.report.reportsource.IReportSource;
publicclassReportInit
{
privateIReportSourcerptSource;
privateFieldsfields;
publicReportInit(){
rptSource=null;
fields=null;
}
publicIReportSourcegetRptsource(){
returnrptSource;
}
publicFieldsgetFields(){
returnfields;
}
publicbooleansetReport(Stringfname,StringrptID){
//取得查询前提
StringFileName=fname+".rpt";
StringBH=rptID;
Stringpath="report/"+FileName;//报表文件路径
try{
IReportSourceFactory2rsf=newJPEReportSourceFactory();
java.util.Localelocaletest=java.util.Locale.CHINA;
rptSource=(IReportSource)rsf.createReportSource(path,localetest);
fields=newFields();
ParameterFieldpfield1=newParameterField();//编号
ParameterFieldpfield2=newParameterField();//单元
ParameterFieldpfield3=newParameterField();//人
ParameterFieldpfield5=newParameterField();//FIELD5
ParameterFieldpfield6=newParameterField();//FIELD6
ParameterFieldpfield4_KSSJ=newParameterField();//入手下手工夫
ParameterFieldpfield4_JSSJ=newParameterField();//停止工夫
Valuesvals1=newValues();
Valuesvals2=newValues();
Valuesvals3=newValues();
Valuesvals5=newValues();
Valuesvals6=newValues();
Valuesvals4_KSSJ=newValues();
Valuesvals4_JSSJ=newValues();
ParameterFieldDiscreteValuepfieldDV1=newParameterFieldDiscreteValue();
ParameterFieldDiscreteValuepfieldDV2=newParameterFieldDiscreteValue();
ParameterFieldDiscreteValuepfieldDV3=newParameterFieldDiscreteValue();
ParameterFieldDiscreteValuepfieldDV5=newParameterFieldDiscreteValue();
ParameterFieldDiscreteValuepfieldDV6=newParameterFieldDiscreteValue();
ParameterFieldDiscreteValuepfieldDV4_KSSJ=newParameterFieldDiscreteValue();
ParameterFieldDiscreteValuepfieldDV4_JSSJ=newParameterFieldDiscreteValue();
//设置第一个参数:编号
pfield1.setReportName("");
pfield1.setName("BH");
pfieldDV1.setValue(BH);
pfieldDV1.setDescription("编号");
vals1.add(pfieldDV1);
pfield1.setCurrentValues(vals1);
//设置第二个参数:单元部门
pfield2.setReportName("");
pfield2.setName("DW");
pfieldDV2.setValue("");
pfieldDV2.setDescription("发单部门");
vals2.add(pfieldDV2);
pfield2.setCurrentValues(vals2);
//设置第三个参数:人
pfield3.setReportName("");
pfield3.setName("REN");
pfieldDV3.setValue("");
pfieldDV3.setDescription("请求人、下达人、操纵人、卖力人等");
vals3.add(pfieldDV3);
pfield3.setCurrentValues(vals3);
//设置第五个查询字段
pfield5.setReportName("");
pfield5.setName("FIELD5");
pfieldDV5.setValue("");
pfieldDV5.setDescription("查询字段5:义务来历线路称号等");
vals5.add(pfieldDV5);
pfield5.setCurrentValues(vals5);
//设置第六个查询字段
pfield6.setReportName("");
pfield6.setName("FIELD6");
pfieldDV6.setValue("");
pfieldDV6.setDescription("查询字段6:变动缘故原由、事情内容等");
vals6.add(pfieldDV6);
pfield6.setCurrentValues(vals6);
//设置入手下手工夫
pfield4_KSSJ.setReportName("");
pfield4_KSSJ.setName("KSSJ");
pfieldDV4_KSSJ.setValue("");
pfieldDV4_KSSJ.setDescription("入手下手工夫");
vals4_KSSJ.add(pfieldDV4_KSSJ);
pfield4_KSSJ.setCurrentValues(vals4_KSSJ);
//设置停止工夫
pfield4_JSSJ.setReportName("");
pfield4_JSSJ.setName("JSSJ");
pfieldDV4_JSSJ.setValue("");
pfieldDV4_JSSJ.setDescription("停止工夫");
vals4_JSSJ.add(pfieldDV4_JSSJ);
pfield4_JSSJ.setCurrentValues(vals4_JSSJ);
//参数字段和报表联系关系
fields.add(pfield1);
fields.add(pfield2);
fields.add(pfield3);
fields.add(pfield5);
fields.add(pfield6);
fields.add(pfield4_KSSJ);
fields.add(pfield4_JSSJ);
returntrue;
}
catch(Exceptione){
System.out.println("Class:ReportInit毛病:"+e);
returnfalse;
}
}
}
//在页面流中增添以下操纵:
/**
*@jpf:action
*@jpf:forwardname="false"path="error.jsp"
*@jpf:forwardname="success"path="viewer.jsp"
*/
protectedForwardshowRpt()
{
Stringrptid=this.getRequest().getParameter("rptID");
StringrptBH=this.getRequest().getParameter("rptBH");
StringrptName=dbCtrl.getRptCNName(rptid);
if((rptName!=null)&&(rptBH!=null)){
ReportInitrpt=newReportInit();
booleanresult=rpt.setReport(rptName,rptBH);
if(result==true){
Fieldsfields=rpt.getFields();
IReportSourcerptSource=rpt.getRptsource();
this.getSession().setAttribute("fields",fields);
this.getSession().setAttribute("rptSource",rptSource);
returnnewForward("success");
}else{
returnnewForward("false");
}
}
returnnewForward("false");
}
//viewer.jsp用来静态显现水晶报表.viewer.jsp的内容以下:
<%@pagelanguage="java"contentType="text/html;charset=utf-8"%>
<%@pageimport="com.crystaldecisions.report.web.viewer.*,
com.crystaldecisions.sdk.occa.report.data.*,
com.crystaldecisions.reports.reportengineinterface.JPEReportSourceFactory,
com.crystaldecisions.sdk.occa.report.reportsource.IReportSourceFactory2,
com.crystaldecisions.sdk.occa.report.reportsource.IReportSource"%>
<%@tagliburi="netui-tags-html.tld"prefix="netui"%>
<%
//fieldsrptSource
//Stringname=(String)request.getAttribute("nametest");
//System.out.println("name="+name);
%>
<!--../crystalreportviewers10/CSS/default.css-->
<LINKrel="stylesheet"type="text/css"href="../crystalreportviewers10/css/default.css">
<%
IReportSourcerptSource=(IReportSource)session.getAttribute("rptSource");
Fieldsfields=(Fields)session.getAttribute("fields");
ConnectionInfosconnInfos=newConnectionInfos();
IConnectionInfoconnInfo1=newConnectionInfo();
connInfo1.setUserName("testuser");
connInfo1.setPassword("test");
connInfos.add(connInfo1);
CrystalReportViewerviewer=newCrystalReportViewer();
viewer.setReportSource(rptSource);
viewer.setDatabaseLogonInfos(connInfos);
viewer.setParameterFields(fields);
viewer.setEnableParameterPrompt(true);
viewer.setOwnPage(true);
viewer.setOwnForm(true);
viewer.setPrintMode(CrPrintMode.ACTIVEX);
viewer.setHasExportButton(true);
viewer.setHasPrintButton(true);
viewer.setHasLogo(false);
viewer.processHttpRequest(request,response,getServletConfig().getServletContext(),out);
viewer.refresh();
//viewer.dispose();
//rptSource.dispose();
%>
再说说缺点:首先java功能强大的背后是其复杂性,就拿web来说,当今流行的框架有很多,什么struts,spring,jQuery等等,而这无疑增加了java的复杂性。 |
|