版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、整合Struts2+JasperReport Web报表应用示例 JasperReports作为一种优秀且开源的报表引擎,不利用太可惜了。同时,借助开源的JasperReports模板设计利器iReports,可以可视化的设计报表模板。基于Web的报表在很多项目中都是需要的。而随着Struts2的流行,就应该研究一下在Struts2下如何利用JasperReports进行报表输出。本示例比较简单,采用的数据源即为JavaBean,而没有采用复杂的数据库,其实原理是一样的。只是传递给JasperReports的参数随着连接方式的变化而略加修改而已。一 准备工作所使用的类库及Jar包如下
2、图所示:图1.使用的Jar包开发环境:MyEclipse5.5+Eclipse3.2+JDK5.0+Tomcat5.5+Struts 2.0.6。当然,本该所提供的源代码下载中没有提供相关的lib,因为文件大太,如果需要,请留下email。源代码下载:Struts2AndJasperReport.rar二 设计报表模板本例中采用JavaBean作为数据源,用于显示People对象的一些基本属性,如所在序号、城市、姓名、地址,并对同一城市的人员进行汇总小结显示。至于如何在iReports中设计模板文件,请在网上参考其它文档。这里不再详细解读,或有时间俺再另写文章来具体讲解如何在iReports中
3、设计报表模板。WebRootjasperjasper_template.jrxml代码如下:<?xml version="1.0" encoding="UTF-8" ?><!- Created with iReport - A designer for JasperReports -><!DOCTYPE jasperReport PUBLIC "/Jasp
4、erReports/DTD Report Design/EN" ""><jasperReport name="jasper_template" columnCount="1"
5、60;printOrder="Vertical" orientation="Portrait" pageWidth="595" pageHeight="842"
6、60; columnWidth="535" columnSpacing="0" leftMargin="30" rightMargin="30"
7、 topMargin="20" bottomMargin="20" whenNoDataType="NoPages"
8、;isTitleNewPage="false" isSummaryNewPage="false"> <property name="ireport.scriptlethandling" value="0" /> <property name="ir
9、eport.encoding" value="UTF-8" /> <import value="java.util.*" /> <import value="net.sf.jasperreports.engine.*" /> <import value="net.sf.jas
10、perreports.engine.data.*" /> <parameter name="rptMan" isForPrompting="false" class="java.lang.String"> <defaultValueExpression ><!CDATA"sterning&qu
11、ot;></defaultValueExpression> </parameter> <parameter name="rptDate" isForPrompting="false" class="java.lang.String"> <defaultValueExpress
12、ion ><!CDATA"2008-01-12"></defaultValueExpression> </parameter> <field name="city" class="java.lang.String"> <fieldDescription>&l
13、t;!CDATAcity></fieldDescription> </field> <field name="street" class="java.lang.String"> <fieldDescription><!CDATAstreet></fieldDescription&g
14、t; </field> <field name="id" class="java.lang.Integer"> <fieldDescription><!CDATAid></fieldDescription> </field>
15、 <field name="name" class="java.lang.String"> <fieldDescription><!CDATAname></fieldDescription> </field> <variable name=&q
16、uot;CityNumber" class="java.lang.Integer" resetType="Group" resetGroup="CityGroup" calculation="Sum"> <initialValueExpression><!CDATA($VCityNumber != null)?(new
17、Integer($VCityNValue() + 1):(new Integer(1)></initialValueExpression> </variable> <variable name="AllCity" class="java.lang.Integer" resetType="Report" calculatio
18、n="Sum"> <initialValueExpression><!CDATA($VAllCity != null)?(new Integer($VAllCValue() + 1):(new Integer(1)></initialValueExpression> </variable>
19、; <group name="CityGroup" > <groupExpression><!CDATA$Fcity></groupExpression> &
20、#160;<groupHeader> <band height="0" isSplitAllowed="true" > </band>
21、160; </groupHeader> <groupFooter> <band height="37" isSplitAllowed="true"
22、; > <staticText> <reportElement
23、160; x="98" y="5" &
24、#160; width="51" height=&quo
25、t;25" key="staticText-8"/>
26、; <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="
27、;#000000"/> <textElement>
28、0;<font fontName="瀹嬩綋" pdfFontName="STSong-Light" size="14" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H"/>
29、160; </textElement> <text><!CDATA灏忚锛歖></text> </staticText>
30、0; <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self&
31、quot; > <reportElement x=&q
32、uot;149" y="5"
33、160; width="34" height="25"
34、60; key="textField-7"/> <box topBorder="None" topBorderColor="#000000" leftBorder="N
35、one" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/> &
36、#160; <textElement> <font fontName="瀹嬩綋" pdfFontName="STSong-Light" size="14"
37、60;isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H"/> </textElement>
38、160; <textFieldExpression class="java.lang.Integer"><!CDATA$VCityGroup_COUNT></textFieldExpression> </textField> &
39、#160; <line direction="TopDown"> <reportElement
40、60; x="-30" y="36"
41、 width="593" height=&q
42、uot;0" key="line-5"/>
43、0;<graphicElement stretchType="NoStretch"/> </line> </band>
44、 </groupFooter> </group> <background> <band height="0" isSp
45、litAllowed="true" > </band> </background> <title>
46、160; <band height="62" isSplitAllowed="true" > <staticText>
47、0; <reportElement x="20" &
48、#160; y="0" width="484" &
49、#160; height="57" forecolor="#FF0033"
50、; key="staticText-1"/> <box topBord
51、er="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
52、160; <textElement textAlignment="Center">
53、; <font fontName="瀹嬩綋" pdfFontName="STSong-Light" size="36" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H"/>
54、60; </textElement> <text><!CDATAStruts2+JasperReports绀轰緥></text>
55、0; </staticText> <line direction="TopDown"> <report
56、Element x="-30"
57、 y="61" width="594"
58、; height="0" key="line-4"/>
59、 <graphicElement stretchType="NoStretch"/> </line> </band
60、> </title> <pageHeader> <band height="13" isSplitAllowed="true" >
61、160; <line direction="TopDown"> <reportElement
62、0; x="-29" y="12" &
63、#160; width="592"
64、0;height="0" key="line-3"/>
65、; <graphicElement stretchType="NoStretch"/> </line> </band> &
66、#160; </pageHeader> <columnHeader> <band height="45" isSplitAllowed="true" >
67、 <staticText> <reportElement &
68、#160; x="13" y="5"
69、 width="62" height="33" &
70、#160; key="staticText-2"/> <box topBorder="None"&
71、#160;topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
72、0; <textElement> <font fontName="瀹嬩綋" p
73、dfFontName="STSong-Light" size="24" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H"/> </textElement>
74、; <text><!CDATA搴忓彿></text> </staticText>
75、0; <staticText> <reportElement
76、; x="98" y="5"
77、0; width="62" height="33"
78、; key="staticText-3"/> <box topBorder="None" topBorderCo
79、lor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
80、160; <textElement> <font fontName="瀹嬩綋" pdfFontName="
81、;STSong-Light" size="24" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H"/> </textElement>
82、60; <text><!CDATA鍩庡競></text> </staticText>
83、160; <staticText> <reportElement
84、60; x="212" y="5" &
85、#160; width="62" height="33"
86、160; key="staticText-4"/> <box topBorder="None" topBorderColor="#0000
87、00" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
88、; <textElement> <font fontName="瀹嬩綋" pdfFontName="STSong-Light&q
89、uot; size="24" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H"/> </textElement>
90、 <text><!CDATA濮撳悕></text> </staticText>
91、; <staticText> <reportElement
92、 x="331" y="5"
93、0; width="62" height="33"
94、; key="staticText-5"/> <box topBorder="None" topBorderColor="#000000" l
95、eftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
96、160; <textElement> <font fontName="瀹嬩綋" pdfFontName="STSong-Light" size=
97、"24" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H"/> </textElement>
98、60; <text><!CDATA浣忓潃></text> </staticText> &l
99、t;line direction="TopDown"> <reportElement
100、0; x="-30" y="43" &
101、#160; width="596" height="0"
102、160; key="line-2"/> <graphicElement stretchType="NoStretch"/>
103、60; </line> </band> </columnHeader> <
104、detail> <band height="43" isSplitAllowed="true" > <textField isStretchWithOv
105、erflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
106、60; <reportElement x="13"
107、 y="7" width="62" &
108、#160; height="30" key="textField-1"/>
109、160; <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000"&
110、#160;bottomBorder="None" bottomBorderColor="#000000"/> <textElement> &
111、#160; <font fontName="瀹嬩綋" pdfFontName="STSong-Light" size="14" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H"/>
112、; </textElement> <textFieldExpression class="java.lang.Integer"><!CDATA$Fid>&
113、lt;/textFieldExpression> </textField> <textField isStretchWithOverflow="false"
114、;isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" > <reportElement
115、60; x="98"
116、;y="7" width="105"
117、; height="29" key="textField-2"/>
118、 <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None
119、" bottomBorderColor="#000000"/> <textElement>
120、; <font fontName="瀹嬩綋" pdfFontName="STSong-Light" size="14" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H"/>
121、60; </textElement> <textFieldExpression class="java.lang.String"><!CDATA$Fcity></textFieldExpression>
122、 </textField> <textField isStretchWithOverflow="false" isBlankWhenNull="fals
123、e" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" > <reportElement
124、 x="212" y="8"
125、0; width="100" h
126、eight="28" key="textField-3"/>
127、160; <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderCo
128、lor="#000000"/> <textElement> &
129、#160; <font fontName="瀹嬩綋" pdfFontName="STSong-Light" size="14" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H"/>
130、; </textElement> <textFieldExpression class="java.lang.String"><!CDATA$Fname></textFieldExpression>
131、160; </textField> <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTim
132、e="Now" hyperlinkType="None" hyperlinkTarget="Self" > <reportElement
133、160; x="331" y="7"
134、 width="111" height="30"
135、 key="textField-4"/> <box
136、60;topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/&g
137、t; <textElement> <font f
138、ontName="瀹嬩綋" pdfFontName="STSong-Light" size="14" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H"/> &
139、#160;</textElement> <textFieldExpression class="java.lang.String"><!CDATA$Fstreet></textFieldExpression>
140、160; </textField> <line direction="TopDown">
141、60; <reportElement x="-30"
142、; y="37" width="593"
143、0; height="0" key="line-1"/>
144、; <graphicElement stretchType="NoStretch"/> </line>
145、160; </band> </detail> <columnFooter> <band height="37" isSplitAl
146、lowed="true" > </band> </columnFooter> <pageFooter>
147、 <band height="50" isSplitAllowed="true" > <textField isStretchWithOverflow="false" isBlankWhenNull="false&
148、quot; evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" > <reportElement
149、160; x="98" y="18"
150、 width="138" hei
151、ght="23" key="textField-8"/>
152、0; <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColo
153、r="#000000"/> <textElement textAlignment="Right">
154、160; <font fontName="瀹嬩綋" pdfFontName="STSong-Light" size="12" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H"/>
155、 </textElement> <textFieldExpression class="java.lang.String"><!CDATA"椤垫暟 " +&
156、#160;String.valueOf($VPAGE_NUMBER) + " of"></textFieldExpression> </textField>
157、60; <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Report" hyperlinkType="None" hyperlinkTarget="Self" >
158、; <reportElement x="239" &
159、#160; y="18" width="83" &
160、#160; height="23" key="textField-9"/>
161、160; <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None&
162、quot; rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/> <textElement> &
163、#160; <font fontName="瀹嬩綋" pdfFontName="STSong-Light" size="12" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2
164、-H"/> </textElement> <textFieldExpression class=&quo
165、t;java.lang.String"><!CDATA" " + String.valueOf($VPAGE_NUMBER)></textFieldExpression> </textField>
166、160; </band> </pageFooter> <lastPageFooter> <band height="50" isSplitAllowed=
167、"true" > </band> </lastPageFooter> <summary> <
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026及未来5年中国多功能滚轮架数据监测研究报告
- 2026事业单位工勤技能-甘肃-甘肃保健按摩师四级(中级工)历年参考题库含答案详解3套试卷
- 2026事业单位工勤技能-湖南-湖南水土保持工三级(高级工)历年参考题库含答案详解3套试卷
- 2026事业单位工勤技能-湖南-湖南农机驾驶维修工五级(初级工)历年参考题库含答案详解3套试卷
- 2026事业单位工勤技能-湖北-湖北热力运行工四级(中级工)历年参考题库含答案详解3套试卷
- 2026事业单位工勤技能-湖北-湖北地图绘制员五级(初级工)历年参考题库含答案详解3套试卷
- 2026事业单位工勤技能-海南-海南舞台技术工四级(中级工)历年参考题库含答案详解3套试卷
- 2026事业单位工勤技能-浙江-浙江机械冷加工一级(高级技师)历年参考题库含答案详解3套试卷
- 2026事业单位工勤技能-江苏-江苏舞台技术工五级(初级工)历年参考题库含答案详解3套试卷
- 2026事业单位工勤技能-上海-上海防疫员五级(初级工)历年参考题库含答案详解3套试卷
- 2026年苏教版七年级下册数学期末学业检测卷(含答案可下载)
- 2025年贵州黔南人力资源开发有限责任公司招聘劳务派遣制专职民兵教练员5人笔试备考试题及答案解析
- 2026年广西公务员申论试题解析及答案
- 《五粮浓香型白酒智能化酿造体系要求》编制说明
- 2025海南国资运营旗下国改基金公司招聘4人笔试历年难易错考点试卷带答案解析
- 2026年及未来5年市场数据中国采购代理行业市场发展数据监测及投资战略咨询报告
- 2026年单细胞多组学技术在肿瘤微环境研究中的突破应用
- 三一重工销售员奖惩制度
- 2025年工厂化学品安全操作培训
- VDA 5 测量过程能力培训课件
- 租用充电桩协议书
评论
0/150
提交评论