瀹為檯搴旂敤涓€氳繃绋嬪簭鍔ㄦ€佷慨鏀規姤琛ㄦā鏉跨殑鎯呭喌寰堝父瑙侊紝鍏朵腑鍔ㄦ€佷慨鏀規暟鎹簮SQL灏辨槸涓€绉嶅吀鍨嬪満鏅€傚父瑙佷簬绯葷粺涓湁涓€浜涚粨鏋勭浉鍚岃€屾暟鎹簮涓嶅悓鐨勬姤琛紝涓哄噺灏戞姤琛ㄥ紑鍙戝伐浣滈噺锛屽彧寮€鍙戜竴濂楁姤琛ㄦā鏉匡紝浣跨敤鏃堕€氳繃绋嬪簭鍔ㄦ€佷慨鏀規暟鎹簮鏉ユ弧瓒沖疄闄呴渶瑕併€?
聽聽涓嬮潰閫氳繃涓€涓嬌鐢↗AVA绋嬪簭淇敼闆嗙畻鎶ヨ〃鏁版嵁婧怱QL鐨勪緥瀛愯鏄庝嬌鐢ㄨ繃绋嬨€?
缂栬緫鎶ヨ〃妯℃澘锛?
鐢變簬涓嶅悓鏁版嵁婧愮殑瀛楁涓嶅悓锛屽洜姝よ繖閲屼嬌鐢ㄥ姩鎬佽〃杈懼紡ds1.fname()鑾峰彇瀛楁鍚嶏紝ds1.field()鑾峰彇瀛楁鍊箋€傛澶栵紝绗竴琛屽拰绗竴鍒椾負杈呭姪琛屽垪锛岃缃叾闅愯棌銆?
聽
缂栧啓浠g爜锛?
1.璇誨叆鎶ヨ〃
String reportPath = request.getRealPath("/reportFiles/demo.rpx");
聽聽聽 ReportDefine rd = (ReportDefine)ReportUtils.read(reportPath);
聽
2.鏇存敼鎶ヨ〃鏁版嵁婧?
DataSetMetaData dsmd=new聽DataSetMetaData();聽聽聽//鏋勯€犳暟鎹泦鍏冩暟鎹?
聽聽聽 SQLDataSetConfig sdc=new聽SQLDataSetConfig();聽聽聽//鏋勯€犳暟鎹泦瀹氫箟
聽聽聽 sdc.setName("ds1");聽聽聽//璁劇疆鏁版嵁闆嗗悕
聽聽聽 Stringsql =聽"";
聽聽聽聽//鏍規嵁涓嶅悓鍙傛暟锛屼負鎶ヨ〃璁劇疆涓嶅悓鏁版嵁婧怱QL锛屽疄闄呬嬌鐢ㄤ腑鍙互浠庨厤缃枃浠朵腑璇誨彇
聽聽聽聽switch(Integer.parseInt(type)){
聽 聽 聽聽聽case聽1:
聽聽聽聽聽聽聽聽聽聽 sql="select * from聽EMPLOYEE";
聽聽聽聽聽聽 聽聽聽聽break;
聽聽聽聽聽聽聽case聽2:
聽聽聽聽聽聽聽聽聽聽 sql="select * from聽PERFORMANCE";
聽聽聽聽聽聽聽聽聽聽聽break;
聽聽聽聽聽聽聽default:sql="select * from聽CUSTOMER";
聽聽聽 }
聽聽聽 sdc.setSQL(sql);聽聽聽聽//璁劇疆聽sql璇彞
聽聽聽 dsmd.addDataSetConfig(sdc);聽聽聽//鎶婃暟鎹泦瀹氫箟娣誨姞鍒版暟鎹泦鍏冩暟鎹?
聽聽聽 rd.setDataSetMetaData(dsmd);聽聽聽//鎶婃暟鎹泦鍏冩暟鎹祴缁橰eportDefine
聽
3.聽聽聽聽聽聽灏哛eportDefine瀛樺叆request鍚庝嬌鐢╠efineBean鏂瑰紡鍙戝竷鎶ヨ〃
聽聽聽 rd.setDataSetMetaData(dsmd);聽聽聽//鎶婃暟鎹泦鍏冩暟鎹祴缁橰eportDefine
聽聽聽 request.setAttribute("reportDefine",rd);
聽
聽聽聽聽聽聽聽聽聽<report:html聽name="report1"
聽聽聽 聽聽聽聽聽聽聽srcType="defineBean"
聽聽聽 聽聽聽聽聽聽聽beanName="reportDefine"
聽聽聽 聽聽聽聽聽聽聽exceptionPage="/reportJsp/jsp/myError.jsp"
聽聽/>
聽
瀹炵幇鏁堟灉锛?
聽聽褰搕ype=1鏃舵樉绀篹mployee琛ㄦ暟鎹細
聽
聽 聽褰搕ype=2鏃舵樉绀篜ERFORMANCE琛ㄦ暟鎹細
聽 聽
銆愰檮銆慶hangeds.jsp瀹屾暣浠g爜锛?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | <%@ page contentType="text/html;charset=GBK"%> <%@ taglib uri="/WEB-INF/raqsoftReport.tld"prefix="report" %> <%@ page import="java.io.*"%> <%@ page import="java.util.*"%> <%@ page import="com.raqsoft.report.usermodel.Context"%> <%@ page import="com.raqsoft.report.model.ReportDefine"%> <%@ page import="com.raqsoft.report.util.ReportUtils"%> <%@page import="com.raqsoft.report.usermodel.SQLDataSetConfig"%> <%@page import="com.raqsoft.report.usermodel.DataSetMetaData"%> 聽聽 聽聽 <html> <link type="text/css"href="css/style.css" target="_blank" rel="external nofollow" rel="stylesheet"/> <body topmargin=0 leftmargin=0 rightmargin=0 bottomMargin=0> <% 聽 聽 request.setCharacterEncoding("GBK"); 聽 聽 String type = request.getParameter("type"); 聽 聽 String reportPath = request.getRealPath("/WEB-INF/reportFiles/test.rpx");聽 聽 聽 ReportDefine rd = (ReportDefine)ReportUtils.read(reportPath);聽 聽 聽 DataSetMetaData dsmd=new DataSetMetaData(); 聽聽 聽 聽 SQLDataSetConfig sdc=new SQLDataSetConfig(); 聽聽 聽 聽 sdc.setName("ds1"); 聽聽 聽 聽 String sql = ""; 聽 聽 switch(Integer.parseInt(type)){ 聽 聽 聽 聽case 1: 聽 聽 聽 聽 聽 聽sql="select * from EMPLOYEE"; 聽 聽 聽 聽 聽 聽break; 聽 聽 聽 聽case 2: 聽 聽 聽 聽 聽 聽sql="select * from PERFORMANCE"; 聽 聽 聽 聽 聽 聽break; 聽 聽 聽 聽default:sql="select * from CUSTOMER"; 聽 聽 } 聽 聽 sdc.setSQL(sql); 聽聽 聽 聽 dsmd.addDataSetConfig(sdc); 聽聽 聽 聽 rd.setDataSetMetaData(dsmd); 聽 聽 聽String rptName = "RPT_"+Double.toString(Math.random()); 聽 聽 request.setAttribute(rptName,rd); 聽 聽 聽 %> 聽 <jsp:include page="toolbar.jsp"flush="false" /> <table id="rpt"align="center" width=100% height=100%> 聽 聽 <tr><td align=center valign=top height=100%> 聽 聽 聽 聽<report:html name="report1"聽 聽 聽 聽 聽 聽 聽srcType="defineBean" 聽 聽 聽 聽 聽 聽 beanName="<%=rptName%>" 聽 contextName="myContext" 聽 聽 聽 聽 聽 聽exceptionPage="/reportJsp/jsp/myError.jsp" 聽 />聽 聽 聽 </td></tr> </table> 聽聽 </body> </html> |