lgnore pagination 鍕鵑変笂錛屽氨鍙互鍙栨秷鍒嗛〉鍔熻兘銆?br />
瑕佽繍琛屾墦鍗扮殑applet闇瑕乯asperreports-x.x.x-applet.jar錛屽彲浠ョ敤winrar鐩存帴瑙e帇緙╀簡錛?br />鐒跺悗鎶奱pplet緙栬緫鍚庣殑class鍜岃В鍘嬬緝鍚庣殑鏂囦歡鏀懼湪鍚屼竴涓洰褰曪紙姣斿temp錛夛紝
鍦ㄥ懡浠ゆ彁紺虹涓緭鍏?jar 鍛戒護鎵撴垚涓涓寘錛屼緥濡傦細jar -cvf stengReport1Applet.jar *
鎺ョ潃寮濮嬪仛鏁板瓧絳懼悕錛?/p>
(1)鐢熸垚璇佷功: keytool -genkey -alias printkey -dname "CN=stsoft, OU=stsoft, O=stsoft, L=nc, ST=nc, C=cn" -keystore printstore -keypass supervise -storepass supervise -validity 3650
榛樿鐨勭鍚嶅彧鏈夊崐騫寸殑鏈夋晥鏈燂紝榪欓噷鎴戜滑鐢?validity鍙傛暟璁懼畾涓?0騫寸殑鏈夋晥鏈?br /> (2)瀵煎嚭璇佷功: keytool -export -keystore printstore -alias printkey -file print.cer -storepass supervise
(3)瀵筳ar鍖呯鍚嶏細
jarsigner -keystore printstore stengReport1Applet.jar printkey
jarsigner -keystore printstore commons-collections-2.1.1.jar printkey
jarsigner -keystore printstore commons-digester-2.1.jar printkey
jarsigner -keystore printstore commons-logging-1.1.1.jar printkey
jarsigner -keystore printstore jasperreports-5.2.0.jar printkey
jarsigner -keystore printstore jasperreports-applet-5.2.0.jar printkey
jarsigner -keystore printstore jasperreports-fonts-5.2.0.jar printkey
jarsigner -keystore printstore jasperreports-javaflow-5.2.0.jar printkey
鐜板湪鍦╰emp涓嬪凡緇忔湁浜嗕竴涓猻tengReport1Applet.jar鍜屼竴涓猵rint.cer錛屾妸榪欎袱涓枃浠舵嫹璐濆洖欏圭洰涓紝璁板緱榪樻槸鏀懼湪鍚屼竴涓洰褰曚笅
榪愯demo紺轟緥涓殑jasper-webapp錛岃闂畃rint.html鍜屽唴宓屽紡viewer.html
涓夈乻truts.xml閰嶇疆
------------------------
struts2涓殑闇緇ф壙jasperreports-default鍛藉悕絀洪棿
<package name=“default” extends="struts-default, jasperreports-default">
<!-- 鎶ヨ〃杈撳嚭Action -->
<action name="JR_*_*" class="jasperReportAction">
<result name="success" type="jasper">
<param name="location">/reports/{1}.jasper</param>
<param name="connection">connection</param>
<param name="format">{2}</param>
<param name="documentName">{1}</param>
<param name="reportParameters">para</param>
<param name="imageServletUrl"><![CDATA[/image?image=]]></param>
</result>
</action>
</package>
location - 鎻愪緵鍒╃敤iReport鍒朵綔緙栬瘧濂界殑鎶ヨ〃鏂囦歡銆?br /> dataSource - 鏁版嵁婧?br /> format - 鎶ヨ〃杈撳嚭鏍煎紡
reportParameters - 鎶ヨ〃鍙傛暟
鍥涖亀eb.xml閰嶇疆
---------------------
鎶ヨ〃鐢熸垚html闇閰嶇疆/image
<!-- jasperreports鎶ヨ〃鐨勯厤緗?start -->
<servlet>
<servlet-name>JasperReportImageServlet</servlet-name>
<servlet-class>net.sf.jasperreports.j2ee.servlets.ImageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>JasperReportImageServlet</servlet-name>
<url-pattern>/image</url-pattern>
</servlet-mapping>
<!-- jasperreports鎶ヨ〃鐨勯厤緗?end -->
浜屻丮ap鏁扮粍錛圡ap Datasources錛?
鏈夌殑鏃跺欐暟鎹笉涓瀹氳浠庢暟鎹簱閲岄潰鏉ワ紝榪樻湁鍙兘浠嶮ap鏁扮粍閲岄潰鏉ユ垚鐢烳ap[]鐨勬柟娉?
private Map[] initializeMapArray()
{
//浣犲彲浠ユ妸鏁扮粍閲岄潰鐨勬瘡涓猰ap鐪嬫垚涓涓璞★紝灝辯浉浜庢暟鎹簱閲岄潰鐨勬瘡涓瓧孌?br />HashMap[] reportRows = new HashMap[4];
HashMap row1Map = new HashMap();
HashMap row2Map = new HashMap();
HashMap row3Map = new HashMap();
HashMap row4Map = new HashMap();
row1Map.put("tail_num", "N263Y");
row1Map.put("aircraft_serial", "T-11");
row1Map.put("aircraft_model", "39 ROSCOE TRNR RACER");
row1Map.put("engine_model", "R1830 SERIES");
row2Map.put("tail_num", "N4087X");
row2Map.put("aircraft_serial", "BA100-163");
row2Map.put("aircraft_model", "BRADLEY AEROBAT");
row2Map.put("engine_model", "R2800 SERIES");
row3Map.put("tail_num", "N43JE");
row3Map.put("aircraft_serial", "HAYABUSA 1");
row3Map.put("aircraft_model", "NAKAJIMA KI-43 IIIA");
row3Map.put("engine_model", "R1830 SERIES");
row4Map.put("tail_num", "N912S");
row4Map.put("aircraft_serial", "9973CC");
row4Map.put("aircraft_model", "PA18-150");
row4Map.put("engine_model", "R-1820 SER");
reportRows[0] = row1Map;
reportRows[1] = row2Map;
reportRows[2] = row3Map;
reportRows[3] = row4Map;
return reportRows;
}
鐢熸垚JRMapArrayDataSource瀵硅薄
private JRDataSource createReportDataSource()
{
JRMapArrayDataSource dataSource;
Map[] reportRows = initializeMapArray();
dataSource = new JRMapArrayDataSource(reportRows);
return dataSource;
}
涓夈丮ap闆嗗悎
private JRDataSource createReportDataSource()
{
JRMapCollectionDataSource dataSource;
Collection reportRows = initializeMapCollection();
dataSource = new JRMapCollectionDataSource(reportRows);
return dataSource;
}
private Collection initializeMapCollection()
{
ArrayList reportRows = new ArrayList();
HashMap row1Map = new HashMap();
HashMap row2Map = new HashMap();
HashMap row3Map = new HashMap();
HashMap row4Map = new HashMap();
row1Map.put("tail_num", "N263Y");
row1Map.put("aircraft_serial", "T-11");
row1Map.put("aircraft_model", "39 ROSCOE TRNR RACER");
row1Map.put("engine_model", "R1830 SERIES");
row2Map.put("tail_num", "N4087X");
row2Map.put("aircraft_serial", "BA100-163");
row2Map.put("aircraft_model", "BRADLEY AEROBAT");
row2Map.put("engine_model", "R2800 SERIES");
row3Map.put("tail_num", "N43JE");
row3Map.put("aircraft_serial", "HAYABUSA 1");
row3Map.put("aircraft_model", "NAKAJIMA KI-43 IIIA");
row3Map.put("engine_model", "R1830 SERIES");
row4Map.put("tail_num", "N912S");
row4Map.put("aircraft_serial", "9973CC");
row4Map.put("aircraft_model", "PA18-150");
row4Map.put("engine_model", "R-1820 SER");
reportRows.add(row1Map);
reportRows.add(row2Map);
reportRows.add(row3Map);
reportRows.add(row4Map);
return reportRows;
}
JRDataSource dataSource = createReportDataSource();
JasperRunManager.runReportToPdfStream(reportStream,
servletOutputStream, new HashMap(), dataSource);
鍥涖佸璞℃暟緇勶紙Java Objects as Datasources錛夊璞AVABEAN
private JRDataSource createReportDataSource()
{
JRBeanArrayDataSource dataSource;
AircraftData[] reportRows = initializeBeanArray();
dataSource = new JRBeanArrayDataSource(reportRows);
return dataSource;
}
private AircraftData[] initializeBeanArray()
{
AircraftData[] reportRows = new AircraftData[4];
reportRows[0] = new AircraftData("N263Y", "T-11", "39 ROSCOE TRNR
RACER", "R1830 SERIES");
reportRows[1] = new AircraftData("N4087X", "BA100-163", "BRADLEY
AEROBAT", "R2800 SERIES");
reportRows[2] = new AircraftData("N43JE", "HAYABUSA 1", "NAKAJIMA
KI-43 IIIA", "R1830 SERIES");
reportRows[3] = new AircraftData("N912S", "9973CC", "PA18-150",
"R-1820 SER");
return reportRows;
}
//鏈鍚巗ervlet閲岄潰璋冪敤
JRDataSource dataSource = createReportDataSource();
JasperRunManager.runReportToPdfStream(reportStream,
servletOutputStream, new HashMap(), dataSource);
浜斻佸璞¢泦鍚?
鍜屽璞℃暟緇勫熀鏈笂涓鏍?灝辨槸鏈鍚庣敓鎴愮殑鏄疛RBeanCollectionDataSource
private JRDataSource createReportDataSource()
{
JRBeanCollectionDataSource dataSource;
Collection reportRows = initializeBeanCollection();
dataSource = new JRBeanCollectionDataSource(reportRows);
return dataSource;
}
JRDataSource dataSource = createReportDataSource();
JasperRunManager.runReportToPdfStream(reportStream,
servletOutputStream, new HashMap(), dataSource);
鍏乆ML鏁版嵁鎴愮敓鎶ヨ〃錛圶ML as Datasource錛?br />
JRXmlDataSource xmlDataSource = new JRXmlDataSource(
new BufferedInputStream(getServletConfig().getServletContext()
.getResourceAsStream("/reports/AircraftData.xml")),
"/AircraftData/aircraft");
涓冦乯son鏁版嵁婧?
ireport閰嶇疆鎴浘錛?br />