锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲AV成人无码天堂,亚洲AV无码国产丝袜在线观看,日韩精品成人亚洲专区http://m.tkk7.com/ec2008/category/26384.html路鍙や箣瀛﹁呭繀鏈夊笀路鍋氬鑰呬害瑕佸仛甯堣吢稦IGHTING路zh-cnFri, 25 Apr 2008 14:34:42 GMTFri, 25 Apr 2008 14:34:42 GMT60榪炴帴鍚勭鏁版嵁搴撴柟寮忛熸煡琛?/title><link>http://m.tkk7.com/ec2008/archive/2008/04/25/196000.html</link><dc:creator>鏈堣娊鍎?/dc:creator><author>鏈堣娊鍎?/author><pubDate>Fri, 25 Apr 2008 08:07:00 GMT</pubDate><guid>http://m.tkk7.com/ec2008/archive/2008/04/25/196000.html</guid><wfw:comment>http://m.tkk7.com/ec2008/comments/196000.html</wfw:comment><comments>http://m.tkk7.com/ec2008/archive/2008/04/25/196000.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/ec2008/comments/commentRss/196000.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/ec2008/services/trackbacks/196000.html</trackback:ping><description><![CDATA[榪炴帴鍚勭鏁版嵁搴撴柟寮忛熸煡琛?br /> <br /> 涓嬮潰緗楀垪浜嗗悇縐嶆暟鎹簱浣跨敤JDBC榪炴帴鐨勬柟寮忥紝鍙互浣滀負涓涓墜鍐屼嬌鐢ㄣ?<br /> <br /> 1銆丱racle8/8i/9i鏁版嵁搴擄紙thin妯″紡錛?<br /> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: #000000;">Class.forName(</span><span style="color: #000000;">"</span><span style="color: #000000;">oracle.jdbc.driver.OracleDriver</span><span style="color: #000000;">"</span><span style="color: #000000;">).newInstance(); <br /> String url</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">jdbc:oracle:thin:@localhost:1521:orcl</span><span style="color: #000000;">"</span><span style="color: #000000;">; </span><span style="color: #008000;">//</span><span style="color: #008000;">orcl涓烘暟鎹簱鐨凷ID </span><span style="color: #008000;"><br /> </span><span style="color: #000000;">String user</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">test</span><span style="color: #000000;">"</span><span style="color: #000000;">; <br /> String password</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">test</span><span style="color: #000000;">"</span><span style="color: #000000;">; <br /> Connection conn</span><span style="color: #000000;">=</span><span style="color: #000000;"> DriverManager.getConnection(url,user,password);  <br /> </span></div> 2銆丏B2鏁版嵁搴?<br /> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: #000000;">Class.forName(</span><span style="color: #000000;">"</span><span style="color: #000000;">com.ibm.db2.jdbc.app.DB2Driver </span><span style="color: #000000;">"</span><span style="color: #000000;">).newInstance(); <br /> String url</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">jdbc:db2://localhost:5000/sample</span><span style="color: #000000;">"</span><span style="color: #000000;">; </span><span style="color: #008000;">//</span><span style="color: #008000;">sample涓轟綘鐨勬暟鎹簱鍚?nbsp;</span><span style="color: #008000;"><br /> </span><span style="color: #000000;">String user</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">admin</span><span style="color: #000000;">"</span><span style="color: #000000;">; <br /> String password</span><span style="color: #000000;">=</span><span style="color: #000000;">""</span><span style="color: #000000;">; <br /> Connection conn</span><span style="color: #000000;">=</span><span style="color: #000000;"> DriverManager.getConnection(url,user,password); <br /> </span></div> 3銆丼ql Server7.0/2000鏁版嵁搴?<br /> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: #000000;"><br /> Class.forName(</span><span style="color: #000000;">"</span><span style="color: #000000;">com.microsoft.jdbc.sqlserver.SQLServerDriver</span><span style="color: #000000;">"</span><span style="color: #000000;">).newInstance(); <br /> String url</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb</span><span style="color: #000000;">"</span><span style="color: #000000;">; <br /> </span><span style="color: #008000;">//</span><span style="color: #008000;">mydb涓烘暟鎹簱 </span><span style="color: #008000;"><br /> </span><span style="color: #000000;">String user</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">sa</span><span style="color: #000000;">"</span><span style="color: #000000;">; <br /> String password</span><span style="color: #000000;">=</span><span style="color: #000000;">""</span><span style="color: #000000;">; <br /> Connection conn</span><span style="color: #000000;">=</span><span style="color: #000000;"> DriverManager.getConnection(url,user,password);  <br /> </span></div> 4銆丼ybase鏁版嵁搴?<br /> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: #000000;">Class.forName(</span><span style="color: #000000;">"</span><span style="color: #000000;">com.sybase.jdbc.SybDriver</span><span style="color: #000000;">"</span><span style="color: #000000;">).newInstance(); <br /> String url </span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;"> jdbc:sybase:Tds:localhost:5007/myDB</span><span style="color: #000000;">"</span><span style="color: #000000;">;</span><span style="color: #008000;">//</span><span style="color: #008000;">myDB涓轟綘鐨勬暟鎹簱鍚?nbsp;</span><span style="color: #008000;"><br /> </span><span style="color: #000000;">Properties sysProps </span><span style="color: #000000;">=</span><span style="color: #000000;"> System.getProperties(); <br /> SysProps.put(</span><span style="color: #000000;">"</span><span style="color: #000000;">user</span><span style="color: #000000;">"</span><span style="color: #000000;">,</span><span style="color: #000000;">"</span><span style="color: #000000;">userid</span><span style="color: #000000;">"</span><span style="color: #000000;">); <br /> SysProps.put(</span><span style="color: #000000;">"</span><span style="color: #000000;">password</span><span style="color: #000000;">"</span><span style="color: #000000;">,</span><span style="color: #000000;">"</span><span style="color: #000000;">user_password</span><span style="color: #000000;">"</span><span style="color: #000000;">); <br /> Connection conn</span><span style="color: #000000;">=</span><span style="color: #000000;"> DriverManager.getConnection(url, SysProps);  <br /> </span></div> 5銆両nformix鏁版嵁搴?<br /> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: #000000;">Class.forName(</span><span style="color: #000000;">"</span><span style="color: #000000;">com.informix.jdbc.IfxDriver</span><span style="color: #000000;">"</span><span style="color: #000000;">).newInstance(); <br /> String url </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">"</span><span style="color: #000000;">jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver; </span><span style="color: #000000;"><br /> </span><span style="color: #000000;">user</span><span style="color: #000000;">=</span><span style="color: #000000;">testuser;password</span><span style="color: #000000;">=</span><span style="color: #000000;">testpassword</span><span style="color: #000000;">"</span><span style="color: #000000;">; //myDB涓烘暟鎹簱鍚?nbsp;</span><span style="color: #000000;"><br /> </span><span style="color: #000000;">Connection conn</span><span style="color: #000000;">=</span><span style="color: #000000;"> DriverManager.getConnection(url);  <br /> </span></div> 6銆丮ySQL鏁版嵁搴?<br /> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: #000000;">Class.forName(</span><span style="color: #000000;">"</span><span style="color: #000000;">org.gjt.mm.mysql.Driver</span><span style="color: #000000;">"</span><span style="color: #000000;">).newInstance(); <br /> String url </span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1</span><span style="color: #000000;">"</span><span style="color: #000000;"> <br /> </span><span style="color: #008000;">//</span><span style="color: #008000;">myDB涓烘暟鎹簱鍚?nbsp;</span><span style="color: #008000;"><br /> </span><span style="color: #000000;">Connection conn</span><span style="color: #000000;">=</span><span style="color: #000000;"> DriverManager.getConnection(url);  <br /> </span></div> 7銆丳ostgreSQL鏁版嵁搴?<br /> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: #000000;">Class.forName(</span><span style="color: #000000;">"</span><span style="color: #000000;">org.postgresql.Driver</span><span style="color: #000000;">"</span><span style="color: #000000;">).newInstance(); <br /> String url </span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">jdbc:postgresql://localhost/myDB</span><span style="color: #000000;">"</span><span style="color: #000000;"> </span><span style="color: #008000;">//</span><span style="color: #008000;">myDB涓烘暟鎹簱鍚?nbsp;</span><span style="color: #008000;"><br /> </span><span style="color: #000000;">String user</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">myuser</span><span style="color: #000000;">"</span><span style="color: #000000;">; <br /> String password</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">mypassword</span><span style="color: #000000;">"</span><span style="color: #000000;">; <br /> Connection conn</span><span style="color: #000000;">=</span><span style="color: #000000;"> DriverManager.getConnection(url,user,password);  <br /> </span></div> 8銆乤ccess鏁版嵁搴撶洿榪炵敤ODBC鐨?br /> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: #000000;"><br /> Class.forName(</span><span style="color: #000000;">"</span><span style="color: #000000;">sun.jdbc.odbc.JdbcOdbcDriver</span><span style="color: #000000;">"</span><span style="color: #000000;">) ;<br /> String url</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=</span><span style="color: #000000;">"</span><span style="color: #000000;">+</span><span style="color: #000000;">application.getRealPath(</span><span style="color: #000000;">"</span><span style="color: #000000;">/Data/ReportDemo.mdb</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br /> Connection conn </span><span style="color: #000000;">=</span><span style="color: #000000;"> DriverManager.getConnection(url,</span><span style="color: #000000;">""</span><span style="color: #000000;">,</span><span style="color: #000000;">""</span><span style="color: #000000;">);<br /> Statement stmtNew</span><span style="color: #000000;">=</span><span style="color: #000000;">conn.createStatement() ; <br /> </span></div> <div style="text-align: right;"><span style="font-size: 8pt;">銆婅漿銆?/span><br /> <br /> </div> <img src ="http://m.tkk7.com/ec2008/aggbug/196000.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/ec2008/" target="_blank">鏈堣娊鍎?/a> 2008-04-25 16:07 <a href="http://m.tkk7.com/ec2008/archive/2008/04/25/196000.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>java鍩虹錛堟寔緇洿鏂頒腑錛?/title><link>http://m.tkk7.com/ec2008/archive/2007/11/04/158125.html</link><dc:creator>鏈堣娊鍎?/dc:creator><author>鏈堣娊鍎?/author><pubDate>Sun, 04 Nov 2007 14:03:00 GMT</pubDate><guid>http://m.tkk7.com/ec2008/archive/2007/11/04/158125.html</guid><wfw:comment>http://m.tkk7.com/ec2008/comments/158125.html</wfw:comment><comments>http://m.tkk7.com/ec2008/archive/2007/11/04/158125.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/ec2008/comments/commentRss/158125.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/ec2008/services/trackbacks/158125.html</trackback:ping><description><![CDATA[<span style="color: #6494a0;">璧勬枡鏀墮泦浜庝簰鑱旂綉錛堝鏈変笉濡ワ紝璇峰憡涔嬶級銆佷釜浜哄績寰椼?/span><br /> <br /> 1.榛樿鐨勬誕鐐圭被鍨嬫槸鍙岀簿搴︼紙double錛夛紝瑕佹兂瑕佷竴涓猣loat蹇呴』鍦ㄦ誕鐐規暟鍚庨潰鍔燜鎴栬協銆傚錛歠loat pi = 3.14;鏄敊璇殑<br /> <br /> 2.嫻偣鍨嬭漿鍖栦負鏁村瀷鏃訛紝涓嶈繘琛屽洓鑸嶄簲鍏ワ紝鐩存帴鎴柇灝忔暟鐐瑰悗闈㈢殑鏁?Java鐨勭被鍨嬫鏌ュ緢涓ユ牸錛屼粠浣庣簿搴﹁漿鎹㈠埌楂樼簿搴︽槸鏃犻』鏄懼紡杞崲鐨勶紝double d = 123;銆備絾鏄弽榪囨潵錛岃繘琛岀獎鍖栬漿鎹紝鐢遍珮綺懼害鍚戜綆綺懼害錛屾垨鑰呬竴縐嶇被鍨嬪埌鍙︿竴縐嶇被鍨嬶紝鍒欏繀欏諱嬌鐢ㄥ己鍒剁被鍨嬭漿鍖栥?br /> <br /> 3.鍦ㄦ暟緇勫0鏄庝腑鍖呭惈鏁扮粍闀垮害姘歌繙鏄笉鍚堟硶鐨勶紒濡傦細int[5] arr; 銆傚洜涓猴紝澹版槑鐨勬椂鍊欏茍娌℃湁瀹炰緥鍖栦換浣曞璞★紝鍙湁鍦ㄥ疄渚嬪寲鏁扮粍瀵硅薄鏃訛紝JVM鎵嶅垎閰嶇┖闂達紝榪欐椂鎵嶄笌闀垮害鏈夊叧銆?br /> <br /> 4.瀵硅薄綾誨瀷鐨勬暟緇勮櫧鐒惰榛樿鍒濆鍖栦簡錛屼絾鏄茍娌℃湁璋冪敤鍏舵瀯閫犲嚱鏁般備篃灝辨槸璇達細Car[] myCar = new Car[10];鍙垱寤轟簡涓涓猰yCar鏁扮粍瀵硅薄錛佸茍娌℃湁鍒涘緩Car瀵硅薄鐨勪換浣曞疄渚嬶紒榪欎笌鍗曠函鐨刵ew涓涓璞′笉鍚岋紒鍗曚釜鐨刵ew瀵硅薄鏃訛紝灝變細璋冪敤鐩稿簲鐨勬瀯閫犲嚱鏁般?br /> <br /> 5.鏁扮粍鏈塴ength灞炴э紝瀛楃涓叉湁length錛堬級鏂規硶<br /> <br /> 6.String涓殑姣忎釜瀛楃閮芥槸涓涓?6浣嶇殑Unicode瀛楃錛岀敤Unicode寰堝鏄撹〃杈句赴瀵岀殑鍥介檯鍖栧瓧絎﹂泦錛屾瘮濡傚緢濂界殑涓枃鏀寔銆俢har涓彲浠ヤ繚瀛樹竴涓腑鏂囨眽瀛楋紝搴斾負char涔熸槸涓涓?6浣嶇殑Unicode瀛楃搴︿負0銆?br /> <br /> 8.String瀵硅薄鏄笉鍙樼殑錛佸彲浠ュ彉鍖栫殑鏄疭tring瀵硅薄鐨勫紩鐢ㄣ?br /> <br /> 9.String鐨勪笉鍙樻х殑鏈哄埗鏄劇劧浼氬湪String甯擱噺鍐呮湁澶ч噺鐨勫啑浣欍傚錛?1" + "2" + "3" +......+ "n" 浜х敓浜唍+(n+1)涓猄tring瀵硅薄錛佸洜姝ava涓轟簡鏇存湁鏁堝湴浣跨敤鍐呭瓨錛孞VM鐣欏嚭涓鍧楃壒孌婄殑鍐呭瓨鍖哄煙錛岃縐頒負“String甯擱噺姹?#8221;銆傚 String澶氫箞鐓ч【鍟婏紒褰撶紪璇戝櫒閬囪String甯擱噺鐨勬椂鍊欙紝瀹冩鏌ヨ姹犲唴鏄惁宸茬粡瀛樺湪鐩稿悓鐨凷tring甯擱噺銆傚鏋滄壘鍒幫紝灝辨妸鏂板父閲忕殑寮曠敤鎸囧悜鐜版湁鐨?String錛屼笉鍒涘緩浠諱綍鏂扮殑String甯擱噺瀵硅薄銆?br /> <br /> 10.java涓殑瀵硅薄鏄湪鍫嗕腑琚垱寤虹殑錛坣ew錛夛紝浣嗗父閲忕被鐨凷tring鏈夌偣鐗瑰埆錛佸儚“haha”榪欐牱鐨勫瓧絎︿覆鏍規嵁絎?鏉℃槸瀛樻斁鍦⊿tring甯擱噺姹犵殑錛岃孲tring s=new String("haha");紜疄鍦ㄥ爢涓鍒涘緩鐨勩?br /> <br /> 11.throw鍜宼hrows鍏抽敭瀛椼倀hrow鐢ㄥ湪鏂規硶浣撲腑鎶涘嚭寮傚父錛屽悗闈㈡槸涓涓叿浣撶殑寮傚父瀵硅薄銆倀hrows鐢ㄥ湪鏂規硶鍙傛暟鍒楄〃鎷彿鐨勫悗闈紝鐢ㄦ潵澹版槑姝ゆ柟娉曚細鎶涘嚭鐨勫紓甯哥綾伙紝鍚庨潰璺熺潃涓涓紓甯哥被銆?br /> <br /> 12.瑕佹妸鐩稿簲鐨凷ystem.out鍜孲ystem.err淇℃伅杈撳叆鍒版枃浠朵腑銆備唬鐮侊細<br /> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: #000000;">        </span><span style="color: #0000ff;">try</span><span style="color: #000000;">   {<br />             System.out.println(</span><span style="color: #000000;">"</span><span style="color: #000000;">娌′笂</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br />             System.setOut(</span><span style="color: #0000ff;">new</span><span style="color: #000000;">   PrintStream(</span><span style="color: #0000ff;">new</span><span style="color: #000000;">   FileOutputStream(</span><span style="color: #0000ff;">new</span><span style="color: #000000;">   File( </span><span style="color: #000000;">"</span><span style="color: #000000;">c:/test.txt </span><span style="color: #000000;">"</span><span style="color: #000000;">))));<br />             System.out.println( </span><span style="color: #000000;">"</span><span style="color: #000000;">haha </span><span style="color: #000000;">"</span><span style="color: #000000;">);<br />             System.out.println(</span><span style="color: #000000;">"</span><span style="color: #000000;">error</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br />         }   </span><span style="color: #0000ff;">catch</span><span style="color: #000000;">   (Exception   e)   {<br />             e.printStackTrace();<br />         }</span></div> err鐨勫惂setOut鏀逛負setErr灝卞彲浠ヤ簡銆?br /> <br /> <br /> <img src ="http://m.tkk7.com/ec2008/aggbug/158125.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/ec2008/" target="_blank">鏈堣娊鍎?/a> 2007-11-04 22:03 <a href="http://m.tkk7.com/ec2008/archive/2007/11/04/158125.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Spring瀹瑰櫒鐨勫惎鍔ㄦ柟娉?/title><link>http://m.tkk7.com/ec2008/archive/2007/10/11/152063.html</link><dc:creator>鏈堣娊鍎?/dc:creator><author>鏈堣娊鍎?/author><pubDate>Thu, 11 Oct 2007 07:50:00 GMT</pubDate><guid>http://m.tkk7.com/ec2008/archive/2007/10/11/152063.html</guid><wfw:comment>http://m.tkk7.com/ec2008/comments/152063.html</wfw:comment><comments>http://m.tkk7.com/ec2008/archive/2007/10/11/152063.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/ec2008/comments/commentRss/152063.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/ec2008/services/trackbacks/152063.html</trackback:ping><description><![CDATA[涓銆佸湪web.xml涓厤緗甋pring瀹瑰櫒鐨勫惎鍔?nbsp;錛堥氱敤鐨勬柟娉曪級<br /> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: #000000;"><</span><span style="color: #000000;">context</span><span style="color: #000000;">-</span><span style="color: #000000;">param</span><span style="color: #000000;">></span><span style="color: #000000;"><br />      </span><span style="color: #000000;"><</span><span style="color: #000000;">param</span><span style="color: #000000;">-</span><span style="color: #000000;">name</span><span style="color: #000000;">></span><span style="color: #000000;">contextConfigLocation</span><span style="color: #000000;"></</span><span style="color: #000000;">param</span><span style="color: #000000;">-</span><span style="color: #000000;">name</span><span style="color: #000000;">></span><span style="color: #000000;"> <br />      </span><span style="color: #000000;"><</span><span style="color: #000000;">param</span><span style="color: #000000;">-</span><span style="color: #000000;">value</span><span style="color: #000000;">>/</span><span style="color: #000000;">WEB</span><span style="color: #000000;">-</span><span style="color: #000000;">INF</span><span style="color: #000000;">/</span><span style="color: #000000;">classes</span><span style="color: #000000;">/</span><span style="color: #000000;">applicationContext.xml</span><span style="color: #000000;"></</span><span style="color: #000000;">param</span><span style="color: #000000;">-</span><span style="color: #000000;">value</span><span style="color: #000000;">></span><span style="color: #000000;">  <br />                        </span><span style="color: #008000;">//</span><span style="color: #008000;">濡傛湁澶氫釜spring閰嶇疆鏂囦歡鐢ㄩ楀彿闅斿紑</span><span style="color: #008000;"><br /> </span><span style="color: #000000;"> </span><span style="color: #000000;"></</span><span style="color: #000000;">context</span><span style="color: #000000;">-</span><span style="color: #000000;">param</span><span style="color: #000000;">></span><span style="color: #000000;"><br />      </span><span style="color: #000000;"><!--</span><span style="color: #000000;"> 閫氳繃Listener閰嶇疆Spring瀹瑰櫒闅廤eb搴旂敤鐨勫惎鍔ㄨ屽垵濮嬪寲 </span><span style="color: #000000;">--></span><span style="color: #000000;"><br /> </span><span style="color: #000000;"><</span><span style="color: #000000;">listener</span><span style="color: #000000;">></span><span style="color: #000000;"><br />      </span><span style="color: #000000;"><</span><span style="color: #000000;">listener</span><span style="color: #000000;">-</span><span style="color: #0000ff;">class</span><span style="color: #000000;">></span><span style="color: #000000;">org.springframework.web.context.ContextLoaderListener</span><span style="color: #000000;"></</span><span style="color: #000000;">listener</span><span style="color: #000000;">-</span><span style="color: #0000ff;">class</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> </span><span style="color: #000000;"></</span><span style="color: #000000;">listener</span><span style="color: #000000;">></span></div> <br /> 浜屻乻truts1鐨勫惎鍔ㄦ柟娉?br /> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: #000000;"><</span><span style="color: #000000;">plug</span><span style="color: #000000;">-</span><span style="color: #000000;">in className</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">org.springframework.web.struts.ContextLoaderPlugIn</span><span style="color: #000000;">"</span><span style="color: #000000;">></span><span style="color: #000000;"><br />     </span><span style="color: #000000;"><</span><span style="color: #000000;">set</span><span style="color: #000000;">-</span><span style="color: #000000;">property property</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">contextConfigLocation</span><span style="color: #000000;">"</span><span style="color: #000000;"> value</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">/WEB-INF/applicationContext.xml,</span><span style="color: #000000;"><br /> </span><span style="color: #000000;">               </span><span style="color: #000000;">/</span><span style="color: #000000;">WEB</span><span style="color: #000000;">-</span><span style="color: #000000;">INF</span><span style="color: #000000;">/</span><span style="color: #000000;">action</span><span style="color: #000000;">-</span><span style="color: #000000;">servlet.xml</span><span style="color: #000000;">"</span><span style="color: #000000;"> /></span><span style="color: #000000;"><br /> </span><span style="color: #000000;"></</span><span style="color: #000000;">plug</span><span style="color: #000000;">-</span><span style="color: #000000;">in</span><span style="color: #000000;">></span></div> <杞?gt;<br /> <img src ="http://m.tkk7.com/ec2008/aggbug/152063.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/ec2008/" target="_blank">鏈堣娊鍎?/a> 2007-10-11 15:50 <a href="http://m.tkk7.com/ec2008/archive/2007/10/11/152063.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>ActionServlet綾?/title><link>http://m.tkk7.com/ec2008/archive/2007/10/11/151961.html</link><dc:creator>鏈堣娊鍎?/dc:creator><author>鏈堣娊鍎?/author><pubDate>Thu, 11 Oct 2007 02:19:00 GMT</pubDate><guid>http://m.tkk7.com/ec2008/archive/2007/10/11/151961.html</guid><wfw:comment>http://m.tkk7.com/ec2008/comments/151961.html</wfw:comment><comments>http://m.tkk7.com/ec2008/archive/2007/10/11/151961.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/ec2008/comments/commentRss/151961.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/ec2008/services/trackbacks/151961.html</trackback:ping><description><![CDATA[    <p class="MsoNormal" style="text-indent: 18pt;"><span style="font-size: 9pt;" lang="EN-US">ActionServlet </span><span style="font-size: 9pt; font-family: 瀹嬩綋;">綾誨搴旂殑綾誨悕涓?/span><span style="font-size: 9pt;" lang="EN-US">org.apche.struts.action.ActionServlet</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">錛屽畠鏄?/span><span style="font-size: 9pt;" lang="EN-US">struts</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">妗嗘灦鐨勬牳蹇冩帶鍒跺櫒緇勪歡錛屾墍鏈夌敤鎴風殑璇鋒眰閮藉厛鐢?/span><span style="font-size: 9pt;" lang="EN-US">ActionServlet</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鏉ュ鐞嗭紝鐒跺悗鍐嶇敱</span><span style="font-size: 9pt;" lang="EN-US">ActionServlet</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鎶婅姹傝漿鍙戠粰鍏朵粬緇勪歡銆?/span><span style="font-size: 9pt;" lang="EN-US"><br /> Struts</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鍙厑璁鎬竴涓簲鐢ㄤ腑閰嶇疆涓涓?/span><span style="font-size: 9pt;" lang="EN-US"> ActionServlet</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">錛屼絾鏄彲浠ュ皢</span><span style="font-size: 9pt;" lang="EN-US">ActionServlet</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鎵╁睍銆?/span><span style="font-size: 9pt;" lang="EN-US"><br /> Servlet</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">瀹瑰櫒鍦ㄥ惎鍔ㄦ椂錛屾垨鑰呯敤鎴烽嬈¤姹?/span><span style="font-size: 9pt;" lang="EN-US">ActionServlet</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鏃跺姞杞?/span><span style="font-size: 9pt;" lang="EN-US">ActionServlet</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">綾伙紝鍦ㄤ笂榪版儏鍐典笅錛?/span><span style="font-size: 9pt;" lang="EN-US">Servlet</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">瀹瑰櫒閮戒細鍦?/span><span style="font-size: 9pt;" lang="EN-US">ActionServlet</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">琚姞杞藉悗绔嬪嵆鎵ц瀹冪殑</span><span style="font-size: 9pt;" lang="EN-US">init()</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鏂規硶銆?/span><span style="font-size: 9pt;" lang="EN-US">Init()</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">榪囩▼濡備笅錛?/span><span style="font-size: 9pt;" lang="EN-US"><br /> </span><span style="font-size: 9pt; font-family: 瀹嬩綋;">銆銆</span><span style="font-size: 9pt;" lang="EN-US">1.</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">璋冪敤</span><span style="font-size: 9pt;" lang="EN-US">initInternal()</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鏂規硶錛屽垵濮嬪寲</span><span style="font-size: 9pt;" lang="EN-US">struts</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">妗嗘灦鍐呭湪鐨勬秷鎭祫婧愶紝濡備笌緋葷粺鏃ュ織鐩稿叧鐨勯氱煡銆佽鍛婂拰閿欒淇℃伅銆?/span><span style="font-size: 9pt;" lang="EN-US"><br /> </span><span style="font-size: 9pt; font-family: 瀹嬩綋;">銆銆</span><span style="font-size: 9pt;" lang="EN-US">2.</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">璋冪敤</span><span style="font-size: 9pt;" lang="EN-US">initOther()</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">錛屼粠</span><span style="font-size: 9pt;" lang="EN-US">web.xml</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鏂囦歡涓姞杞?/span><span style="font-size: 9pt;" lang="EN-US">ActionServlet</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鐨勫垵濮嬪寲鍙傛暟錛屽</span><span style="font-size: 9pt;" lang="EN-US">config </span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鍙傛暟</span><span style="font-size: 9pt;" lang="EN-US"><br /> </span><span style="font-size: 9pt; font-family: 瀹嬩綋;">銆銆</span><span style="font-size: 9pt;" lang="EN-US">3.</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">璋冪敤</span><span style="font-size: 9pt;" lang="EN-US">initServlet(),</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">浠?/span><span style="font-size: 9pt;" lang="EN-US">web.xml</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鏂囦歡涓姞杞?/span><span style="font-size: 9pt;" lang="EN-US">ActionServlet</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鐨?/span><span style="font-size: 9pt;" lang="EN-US">URL</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鏄犲皠淇℃伅銆傛澶栬繕浼氭敞鍐?/span><span style="font-size: 9pt;" lang="EN-US">web.xml</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鍜?/span><span style="font-size: 9pt;" lang="EN-US"><br /> struts</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">閰嶇疆鏂囦歡鎵浣跨敤鐨?/span><span style="font-size: 9pt;" lang="EN-US">DTD</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鏂囦歡錛岃繖浜?/span><span style="font-size: 9pt;" lang="EN-US">DTD</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鏂囦歡鐢ㄦ潵楠岃瘉</span><span style="font-size: 9pt;" lang="EN-US">web.xml</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鍜?/span><span style="font-size: 9pt;" lang="EN-US">struts</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">閰嶇疆鏂囦歡鐨勮娉?/span><span style="font-size: 9pt;" lang="EN-US"><br /> </span><span style="font-size: 9pt; font-family: 瀹嬩綋;">銆銆</span><span style="font-size: 9pt;" lang="EN-US">4.</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">璋冪敤</span><span style="font-size: 9pt;" lang="EN-US">initModuleConfig()</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">錛屽姞杞藉茍瑙f瀽榛樿瀛愬簲鐢ㄦā鍧楃殑</span><span style="font-size: 9pt;" lang="EN-US">struts</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">閰嶇疆鏂囦歡錛涘垱寤?/span><span style="font-size: 9pt;" lang="EN-US">ModuleConfig</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">瀵硅薄錛屾妸瀹冨瓨鍦?/span><span style="font-size: 9pt;" lang="EN-US">ServletContext</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">涓?/span><span style="font-size: 9pt;" lang="EN-US">  <br />         5.</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">璋冪敤</span><span style="font-size: 9pt;" lang="EN-US">intiModuleMessageResources()</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">錛屽姞杞藉茍鍒濆鍖栭粯璁ゅ瓙搴旂敤妯″潡鐨勬秷鎭祫婧愶紝鍒涘緩</span><span style="font-size: 9pt;" lang="EN-US"><br /> MessageResources</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">瀵硅薄錛屾妸瀹冨瓨鍦?/span><span style="font-size: 9pt;" lang="EN-US">ServletContext</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">涓?/span><span style="font-size: 9pt;" lang="EN-US"><br />         6.</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">璋冪敤</span><span style="font-size: 9pt;" lang="EN-US">initModuleDataSources()</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鏂規硶錛屽姞杞藉茍鍒濆鍖栭粯璁ゅ瓙搴旂敤妯″潡鐨勬暟鎹簮銆傚鏋滄病鏈夊湪</span><span style="font-size: 9pt;" lang="EN-US">struts</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">閰嶇疆鏂囦歡涓病鏈夊畾涔?/span><span style="font-size: 9pt;" lang="EN-US"><data-sources></span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鍏冪礌錛屽氨蹇界暐榪欎竴嫻佺▼</span><span style="font-size: 9pt;" lang="EN-US"><br />          7.</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">璋冪敤</span><span style="font-size: 9pt;" lang="EN-US">initModulePlugins(),</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鍔犺澆騫跺垵濮嬪寲榛樿瀛愬簲鐢ㄦā鍧楃殑鎵鏈夋彃浠?/span><span style="font-size: 9pt;" lang="EN-US"><br />          8.</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">褰撻粯璁ゅ瓙搴旂敤妯″潡琚垚鍔熷垵濮嬪寲鍚庯紝濡傛灉搴旂敤榪樺寘鎷叾浠栧瓙搴旂敤妯″潡錛屽皢閲嶅嫻佺▼</span><span style="font-size: 9pt;" lang="EN-US">4-7</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">錛屽垎鍒鍏朵粬瀛愬簲鐢ㄦā鍧楄繘琛屽垵濮嬪寲銆傛墿灞?/span><span style="font-size: 9pt;" lang="EN-US">ActionServlet</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">綾伙紝瀹氫箟濡備笅鐨勭被錛?/span><span style="font-size: 9pt;" lang="EN-US"><o:p></o:p></span></p> <span style="font-size: 8pt;"><span style="font-size: 8pt;"><span style="font-size: 36pt;"><span style="font-size: 8pt;"><span style="font-size: 12pt;"><font size="3"> </font> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: #0000ff;">package</span><span style="color: #000000;"> sample;<br /> <br /> <br /> </span><span style="color: #0000ff;">public</span><span style="color: #000000;"> </span><span style="color: #0000ff;">class</span><span style="color: #000000;"> ExtendedActionServlet </span><span style="color: #0000ff;">extends</span><span style="color: #000000;"> ActionServlet {<br />         </span><span style="color: #0000ff;">public</span><span style="color: #000000;"> </span><span style="color: #0000ff;">void</span><span style="color: #000000;"> init() </span><span style="color: #0000ff;">throws</span><span style="color: #000000;"> ServletException {<br />                </span><span style="color: #0000ff;">super</span><span style="color: #000000;">.init();<br />                </span><span style="color: #008000;">//</span><span style="color: #008000;">do some operations</span><span style="color: #008000;"><br /> </span><span style="color: #000000;">               ……………<br />         }<br /> }<br /> <br /> <br /> </span></div> </span></span></span></span></span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鎵╁睍瀹岀被鍚庯紝榪樺簲璇ュ湪</span><span style="font-size: 9pt; font-family: "Times New Roman";" lang="EN-US">web.xml</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">鏂囦歡涓涓嬮厤緗細</span><span style="font-size: 8pt;"><span style="font-size: 8pt;"><span style="font-size: 36pt;"><span style="font-size: 8pt;"><span style="font-size: 12pt;"> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: #000000;"><</span><span style="color: #000000;">servlet</span><span style="color: #000000;">></span><span style="color: #000000;"><br />         </span><span style="color: #000000;"><</span><span style="color: #000000;">servlet</span><span style="color: #000000;">-</span><span style="color: #000000;">name</span><span style="color: #000000;">></span><span style="color: #000000;">sample</span><span style="color: #000000;"></</span><span style="color: #000000;">servlet</span><span style="color: #000000;">-</span><span style="color: #000000;">name</span><span style="color: #000000;">></span><span style="color: #000000;"> </span><span style="color: #000000;"><br /> <</span><span style="color: #000000;">servlet</span><span style="color: #000000;">-</span><span style="color: #0000ff;">class</span><span style="color: #000000;">></span><span style="color: #000000;">sample.ExtendedActionServlet</span><span style="color: #000000;"></</span><span style="color: #000000;">servlet</span><span style="color: #000000;">-</span><span style="color: #0000ff;">class</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> </span><span style="color: #000000;"></</span><span style="color: #000000;">servlet</span><span style="color: #000000;">></span><span style="color: #000000;"><br /> </span><span style="color: #000000;"><</span><span style="color: #000000;">servlet</span><span style="color: #000000;">-</span><span style="color: #000000;">mapping</span><span style="color: #000000;">></span><span style="color: #000000;"><br />        </span><span style="color: #000000;"><</span><span style="color: #000000;">servlet</span><span style="color: #000000;">-</span><span style="color: #000000;">name</span><span style="color: #000000;">></span><span style="color: #000000;">sample</span><span style="color: #000000;"></</span><span style="color: #000000;">servlet</span><span style="color: #000000;">-</span><span style="color: #000000;">name</span><span style="color: #000000;">></span><span style="color: #000000;"><br />        </span><span style="color: #000000;"><</span><span style="color: #000000;">url</span><span style="color: #000000;">-</span><span style="color: #000000;">pattern</span><span style="color: #000000;">>/</span><span style="color: #000000;">action</span><span style="color: #008000;">/*</span><span style="color: #008000;"><url-pattern><br /> //涓婇潰鐨?action/*琛ㄧず璐熻矗澶勭悊鎵鏈変互/action涓哄墠緙鐨刄RL,鍚庨潰鐨?琛ㄧず杞箟<br /> <servlet-mapping><br /> <br /> </span></div> <span id="515nffz" class="01"> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><br /> <span id="jppnzn5" class="01"><span style="font-family: 瀹嬩綋;"><font size="3"></font></span></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span id="3r5xrfv" class="01"></span><span style="font-size: 9pt; font-family: "Times New Roman";" lang="EN-US"><</span><span style="font-size: 9pt; font-family: 瀹嬩綋;">杞?/span><span style="font-size: 9pt; font-family: "Times New Roman";" lang="EN-US">></span><br /> <span style="font-family: 瀹嬩綋;"><font size="3"></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-family: 瀹嬩綋;"><font size="3"><span lang="EN-US"><br /> </span></font></span></p> </span><br /> <br /> </span></span></span></span></span> <img src ="http://m.tkk7.com/ec2008/aggbug/151961.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/ec2008/" target="_blank">鏈堣娊鍎?/a> 2007-10-11 10:19 <a href="http://m.tkk7.com/ec2008/archive/2007/10/11/151961.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>java 鏋勯犲嚱鏁拌皟鐢ㄩ『搴?/title><link>http://m.tkk7.com/ec2008/archive/2007/10/10/151799.html</link><dc:creator>鏈堣娊鍎?/dc:creator><author>鏈堣娊鍎?/author><pubDate>Wed, 10 Oct 2007 08:46:00 GMT</pubDate><guid>http://m.tkk7.com/ec2008/archive/2007/10/10/151799.html</guid><wfw:comment>http://m.tkk7.com/ec2008/comments/151799.html</wfw:comment><comments>http://m.tkk7.com/ec2008/archive/2007/10/10/151799.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/ec2008/comments/commentRss/151799.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/ec2008/services/trackbacks/151799.html</trackback:ping><description><![CDATA[褰撲竴涓鏉傜殑瀵硅薄琚瀯閫犳椂,瀹冪殑鏋勯犲嚱鏁版寜涓嬮潰鐨勯『搴忚璋冪敤(that the order of constructor calls for a complex object is as follows) <p>    1.鍏跺熀綾?base-class)鐨勬瀯閫犲嚱鏁拌璋冪敤,榪欎釜姝ラ浠ラ掑綊鐨勬柟寮忛噸澶?鎵浠ユ渶搴曞眰(the root of hierarchy)鐨勬瀯閫犲嚱鏁伴鍏堣鎵ц,鐒跺悗鏄畠涓婁竴灞傛淳鐢熺被(the next-derived class)...鐩村埌鏈欏跺眰鐨勬淳鐢熺被(the most-derived class).</p> <p>The base-class constructor is called. This step is repeated recursively such that the root of the hierarchy is constructed first, followed by the next-derived class, etc., until the most-derived class is reached.)</p> <p>    2.濡傛灉鏈夊寘鍚叧緋?composition),閭d箞瀹冪殑鎴愬憳瀵硅薄鎸夌収澹版槑鐨勯『搴忚鏋勯?</p> <p>Member initializers are called in the order of declaration.</p> <p>    3.媧劇敓綾繪瀯閫犲嚱鏁扮殑鍐呭(body)琚墽琛?</p> <p>The body of the derived-class constructor is called.</p> <p>    涓涓疄渚?</p> <br /> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: #0000ff;">class</span><span style="color: #000000;"> Cake{<br />    Cake(){System.out.println(</span><span style="color: #000000;">"</span><span style="color: #000000;">Cake()</span><span style="color: #000000;">"</span><span style="color: #000000;">);}<br /> }<br /> <br /> </span><span style="color: #0000ff;">class</span><span style="color: #000000;"> Meal {<br />   Meal() { System.out.println(</span><span style="color: #000000;">"</span><span style="color: #000000;">Meal()</span><span style="color: #000000;">"</span><span style="color: #000000;">); }<br /> }<br /> <br /> </span><span style="color: #0000ff;">class</span><span style="color: #000000;"> Bread {<br />   Bread() { System.out.println(</span><span style="color: #000000;">"</span><span style="color: #000000;">Bread()</span><span style="color: #000000;">"</span><span style="color: #000000;">); }<br /> }<br /> <br /> </span><span style="color: #0000ff;">class</span><span style="color: #000000;"> Cheese {<br />   Cheese() { System.out.println(</span><span style="color: #000000;">"</span><span style="color: #000000;">Cheese()</span><span style="color: #000000;">"</span><span style="color: #000000;">); }<br /> }<br /> <br /> </span><span style="color: #0000ff;">class</span><span style="color: #000000;"> Lettuce {<br />   Lettuce() { System.out.println(</span><span style="color: #000000;">"</span><span style="color: #000000;">Lettuce()</span><span style="color: #000000;">"</span><span style="color: #000000;">); }<br /> }<br /> <br /> </span><span style="color: #0000ff;">class</span><span style="color: #000000;"> Lunch </span><span style="color: #0000ff;">extends</span><span style="color: #000000;"> Meal {<br />   Lunch() { System.out.println(</span><span style="color: #000000;">"</span><span style="color: #000000;">Lunch()</span><span style="color: #000000;">"</span><span style="color: #000000;">); }<br /> }<br /> <br /> </span><span style="color: #0000ff;">class</span><span style="color: #000000;"> PortableLunch </span><span style="color: #0000ff;">extends</span><span style="color: #000000;"> Lunch {<br />    </span><span style="color: #008000;">//</span><span style="color: #008000;">if make derived-class object as the menber of the base-class will lead a infinite<br />    </span><span style="color: #008000;">//</span><span style="color: #008000;">loop and program will stop because of the memory consumed<br />    <br />    </span><span style="color: #008000;">//</span><span style="color: #008000;">private Sandwich s=new Sandwich(); </span><span style="color: #008000;"><br /> </span><span style="color: #000000;">  </span><span style="color: #0000ff;">private</span><span style="color: #000000;"> Cake a</span><span style="color: #000000;">=</span><span style="color: #0000ff;">new</span><span style="color: #000000;"> Cake();<br />   PortableLunch() { System.out.println(</span><span style="color: #000000;">"</span><span style="color: #000000;">PortableLunch()</span><span style="color: #000000;">"</span><span style="color: #000000;">);}<br /> }<br /> <br /> </span><span style="color: #0000ff;">public</span><span style="color: #000000;"> </span><span style="color: #0000ff;">class</span><span style="color: #000000;"> Sandwich </span><span style="color: #0000ff;">extends</span><span style="color: #000000;"> PortableLunch<br /> {<br />   </span><span style="color: #0000ff;">private</span><span style="color: #000000;"> Bread b </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000ff;">new</span><span style="color: #000000;"> Bread();<br />   </span><span style="color: #0000ff;">private</span><span style="color: #000000;"> Cheese c </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000ff;">new</span><span style="color: #000000;"> Cheese();<br />   </span><span style="color: #0000ff;">private</span><span style="color: #000000;"> Lettuce l </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000ff;">new</span><span style="color: #000000;"> Lettuce();<br />   <br />   </span><span style="color: #0000ff;">public</span><span style="color: #000000;"> Sandwich() {<br />     System.out.println(</span><span style="color: #000000;">"</span><span style="color: #000000;">Sandwich()</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br />   }<br />   <br />   </span><span style="color: #0000ff;">public</span><span style="color: #000000;"> </span><span style="color: #0000ff;">static</span><span style="color: #000000;"> </span><span style="color: #0000ff;">void</span><span style="color: #000000;"> main(String[] args)  {<br />     </span><span style="color: #0000ff;">new</span><span style="color: #000000;"> Sandwich();<br />   }<br /> }</span></div> <p>杈撳嚭:</p> <p>Meal()<br /> Lunch()<br /> Cake()<br /> PortableLunch()<br /> Bread()<br /> Cheese()<br /> Lettuce()<br /> Sandwich()</p> <p>   main()鍑芥暟涓鏋勯犱竴涓猄andwich鐨勫璞?璋冪敤(騫朵笉鏄墽琛?瀹冨熀綾籔ortableLunch鐨勬瀯閫犲嚱鏁?PortableLunch鍙堥? 褰掔殑璋冪敤,鐒跺悗鏄疢eal,Meal鏄戶鎵跨殑鏈搴曞眰鐨勫熀綾?涓嶇畻Object)鎵浠ュ畠鐨勬瀯閫犲嚱鏁伴鍏堣鎵ц,鐒跺悗鎸夋搴忚繑鍥炲埌Lunch, PortableLunch,浣嗗湪PortableLunch鐨勬瀯閫犲嚱鏁拌鎵ц涔嬪墠,瀹冪殑鎴愬憳瀵硅薄Cake a鍏堟寜鐓у0鏄庣殑欏哄簭琚瀯閫?鐒跺悗鎵цPortableLunch(),鎺ョ潃鏄疭andwich鐨勬垚鍛樺璞?鏈鍚庢槸Sandwich().</p> <p>娉?琚敞閲婃帀鐨勪唬鐮?灝哹ase-class鐨勫璞′綔涓篸erive-class鐨勬垚鍛樺璞?榪欐牱浼氶掑綊鏃犳硶緇撴潫,鏈鍚庣▼搴忓洜鍫嗘爤鑰楀敖鑰岀粨鏉?Exception in  thread main java.lang.StackOverflowError).</p> <br /> <br /> <p id="TBPingURL">Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1134115(杞?</p> <p><br /> </p> <img src ="http://m.tkk7.com/ec2008/aggbug/151799.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/ec2008/" target="_blank">鏈堣娊鍎?/a> 2007-10-10 16:46 <a href="http://m.tkk7.com/ec2008/archive/2007/10/10/151799.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Subversion(SVN)鐗堟湰鎺у埗瀹夎浣跨敤鎸囧崡http://m.tkk7.com/ec2008/archive/2007/09/17/145881.html鏈堣娊鍎?/dc:creator>鏈堣娊鍎?/author>Mon, 17 Sep 2007 07:49:00 GMThttp://m.tkk7.com/ec2008/archive/2007/09/17/145881.htmlhttp://m.tkk7.com/ec2008/comments/145881.htmlhttp://m.tkk7.com/ec2008/archive/2007/09/17/145881.html#Feedback0http://m.tkk7.com/ec2008/comments/commentRss/145881.htmlhttp://m.tkk7.com/ec2008/services/trackbacks/145881.html闃呰鍏ㄦ枃

]]>
What is Struts? Intro to a framework for web applications浠嬬粛Struts鐨勪竴綃囨枃绔?/title><link>http://m.tkk7.com/ec2008/archive/2007/09/12/144656.html</link><dc:creator>鏈堣娊鍎?/dc:creator><author>鏈堣娊鍎?/author><pubDate>Wed, 12 Sep 2007 15:58:00 GMT</pubDate><guid>http://m.tkk7.com/ec2008/archive/2007/09/12/144656.html</guid><wfw:comment>http://m.tkk7.com/ec2008/comments/144656.html</wfw:comment><comments>http://m.tkk7.com/ec2008/archive/2007/09/12/144656.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/ec2008/comments/commentRss/144656.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/ec2008/services/trackbacks/144656.html</trackback:ping><description><![CDATA[<strong>Introduction</strong> <p class="ttext-western">This Tutorial will explain you, what struts is, how it builds itself up and why it is advantage to use it for your web application. First, I will provide you some informations about Java Servlets, Java Server Pages and Java Beans, because they are parts of struts.</p> <h2>Java Servlets</h2> <p class="ttext-western">Servlets represents java programs that runs on a web server. They allow the developer to produce dynamic web sites with java.</p> <p class="ttext-western">A Servlet has the following tasks</p> <ul> <li> <p class="ttext-western">It reads and processed data, which a user typed in a HTML form on a web page. </p> </li> <li> <p class="ttext-western">If necessary other informations will be processed. For Example what browser or system will be used.</p> </li> <li> <p class="ttext-western">It generate results with the existing data. It calls the business logic directly in the servlet or another class, which contain the logic or executes a database query.</p> </li> <li> <p class="ttext-western">The results will be formated. If the browser. If the Browser expects an answer in the HTML format, then the results must be formatted in accordance with the standard. It is possible to return different formats of data with a servlet. (gif, jpeg, doc, etc.).</p> </li> <li> <p class="ttext-western">Suitable answer parameters are set. Befor the servlet return the data to the browser, it sends some parameter. The parameter contains the format, that will returned by the servlet, what time the browser use to cache the site and some more.</p> </li> <li> <p class="ttext-western">Return the document, in the format that it sends befor, to the browser.</p> </li> </ul> <h2>Java Server Pages (JSP)</h2> <p class="ttext-western">JavaServer Pages (JSP) are text documents, which are similar to HTML Files. But you find also java code in the JSP File. JavaServer Pages allow you to mix regulare, static HTML with dynamic generated contents of servlets. The java code is inserted in the HTML document on a JSP File, differently to a servlet, where the HTML code is embedded in the java code.</p> <strong>Java Beans</strong> <p class="ttext-western">Java Beans are nothing else as classes, which keep a fixed naming convention, defined by Sun, for their event processing and methods. The attributes (variables) of the java beans are private. The access to these attributes is managed by access methods. The java specification specify these access methodes (getter and setter methods). If a java bean contains a attribute name, you can set or get the value of the attributes with the methode setName() or getName().</p> <h2>Business logic</h2> <p class="ttext-western">The business logic is the core of the application. The processes are implemented in the business logic to manage the data. For Example: when someone borrows a book in a library, that is a process in the business logic. The process change the state of the data (is the book borrowsed or not) or reads the state and then provide this information for a dialog.</p> <p class="ttext-western"><br /> </p> <p class="ttext-western">This short outline should be sufficient, in order to understand the structure of struts.</p> <strong>Why is struts helpful?</strong> <h2>Sepration of dialogs and business logic (functionality)</h2> <p lang="de-DE">Some peoples develop web applications with Perl or PHP and implement their SQL Querys and the business logics directly in the HTML document.</p> <p lang="de-DE">The source code looks like the following example:</p> <br /> <div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">html</span><span style="color: rgb(0, 0, 0);">><</span><span style="color: rgb(0, 0, 0);">head</span><span style="color: rgb(0, 0, 0);">><</span><span style="color: rgb(0, 0, 0);">title</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);">Important title</span><span style="color: rgb(0, 0, 0);"></</span><span style="color: rgb(0, 0, 0);">title</span><span style="color: rgb(0, 0, 0);">></</span><span style="color: rgb(0, 0, 0);">head</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">body</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">someScript</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br /> dbConnection </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> openDBConnection(someDB)<br /> resultSet </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> dbConnection.executeQuery(</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">select bookName from books</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)<br /> loop over resultSet{<br />  print (resultSet.field(</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">bookName</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)<br /> }<br /> </span><span style="color: rgb(0, 0, 0);"></</span><span style="color: rgb(0, 0, 0);">someScript</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 0);"></</span><span style="color: rgb(0, 0, 0);">body</span><span style="color: rgb(0, 0, 0);">></</span><span style="color: rgb(0, 0, 0);">html</span><span style="color: rgb(0, 0, 0);">></span></div> <br /> <p lang="en-US">You can develop in this way, when you use java servlets or JSP. It is convenient in small projects. But imagine you have 70 dialogs, many database querys in this dialogs and you want to define a field status, setting if a book is deleted or not.</p> <p class="ttext-western" lang="de-DE">Good luck</p> <p class="ttext-western">In order to alter functions and database querys easily, we should seperate these from the dialogs.</p> <strong>Advantage of separation</strong> <ul> <li> <p class="ttext-western">Changes on the functionality, without working in the dialogs.</p> </li> <li> <p class="ttext-western">Better overview, functionality not mixed with the dialogs.</p> </li> <li> <p class="ttext-western">Easy maintain a application</p> </li> <li> <p class="ttext-western">Different dialogs, but the same functionality</p> </li> </ul> <h2>Central control</h2> <p class="ttext-western">In order to control the interaction between the dialogs and business processes, you need a central control unit. This control unit manage all importants courses of the application, when which business process and which dialog will be used.</p> <p>You have some disadvantages, if you implement the order of the processes directly to the business logic.</p> <ol> <li> <p>You can not reuse a part of the processes. In the following picture the process "Give Money" will bring you to the process "Select sort of icecream" every time. </p> </li> <li> <p>If you want to change the order of the processes or add more options, you have to change it directly in the business logic.</p> </li> </ol> <p><img src="http://www.laliluna.de/assets/images/tutorials/what-is-struts/process.gif" alt="" /><br /> </p> <br /> <h2>Advantages of the central control</h2> <ul> <li> <p class="ttext-western">It is easy to change the order of the business processes.</p> </li> <li> <p class="ttext-western">Better overview, which dialogs will be used on which business processes.</p> </li> <li> <p class="ttext-western"><span>A central place to control the interaction between business processes and dialogs.</span></p> </li> </ul> <h2>Translation into the technical language</h2> <p class="ttext-western"><strong>The name of this model is Model-View-Controller (MVC)</strong></p> <p class="ttext-western"><strong>Model </strong>(business logic / business processes ? Java Beans)</p> <p class="ttext-western"><strong>View</strong> (dialogs ? JavaServer Pages)</p> <p class="ttext-western"><strong>Controller</strong> (central control unit - Java Servlets)</p> <p class="ttext-western">You will find more about the MVC later in this tutorial.</p> <h2>More helpfully capabilities</h2> <h3>Internationalisation</h3> <p class="ttext-western">If you do not want to translate a dialog, you put the dialog texts directly into the JSP File.</p> <div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">html:form action</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">someAction</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />     Please give your name and the book title  </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">br</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />         Name:<br />  </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">html:text property</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/></span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">br</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />       Title:<br />  </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">html:text property</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">title</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/></span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">br</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">html:submit</span><span style="color: rgb(0, 0, 0);">/></span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 0);"></</span><span style="color: rgb(0, 0, 0);">html:form</span><span style="color: rgb(0, 0, 0);">></span></div> <br /> Struts support resources files. In this files you can define a key for a text.<br /> <div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 0);">bookDialog.formIntro</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">Please give your name and the title of the book.<br /> bookDialog.inputName</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">Name:<br /> bookDialog.bookTitle</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">Title:</span></div> <br /> This key can be used to diplay the text in the JSP file.<br /> <div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">html:form action</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">someAction</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">bean:message key</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">bookDialog.formIntro</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/></span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">br</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">bean:message key</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">bookDialog.inputName</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/></span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">html:text property</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/></span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">br</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">bean:message key</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">bookDialog.bookTitle</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/></span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">html:text property</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">title</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/></span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">br</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">html:submit</span><span style="color: rgb(0, 0, 0);">/></span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 0);"></</span><span style="color: rgb(0, 0, 0);">html:form</span><span style="color: rgb(0, 0, 0);">></span></div> <br /> <p class="ttext-western">Struts call the locale specific resource file by using the browser settings. You may overwrite this setting. It is quite easy to build an internationalized application with struts.</p> <h3>Error handling</h3> <p class="ttext-western">Struts saves error messages in the business logic and can display this in the dialogs. You can show all errors or bind an error to a field (ex. Emailaddress incorrect) and show the error beside of it.</p> <p class="ttext-western">The error messages will be added to the resource files, so the errors can be internationalised too.</p> <h3>Validation of input fields</h3> <p class="ttext-western">Whether an input field of a form contains a valid date, an email, a number or something else, in each application you have to check it. Struts supports a complete solution to validate form fields. You only have to define which form field will be checked and which error message will be displayed.</p> <strong>Components of struts</strong> <p class="ttext-western">JavaServer Pages (JSP) take over the role of dialogs in struts,</p> <p class="ttext-western">Java Beans take over the business logic and business processes and</p> <p class="ttext-western">Java Servlets take over the central control unit</p> <p class="ttext-western"><strong>Thats why we talk about three great parts of struts.</strong></p> <p class="ttext-western"><strong>Model </strong>(business logic / business processes ? Java Beans)</p> <p class="ttext-western"><strong>View</strong> (dialogs ? JavaServer Pages)</p> <p class="ttext-western"><strong>Controller</strong> (central control unit - Java Servlets)</p> <p class="ttext-western">The <strong>model</strong> represent the actual state of the application. Two kinds of java beans are used. There are java beans which contains the data of a form or data to display (ex. The books of a library) and java beans which includes the functionality of the application or call the business logic (when a user borrows a book).</p> <p class="ttext-western">The <strong>view component</strong> is responsible for the presentation of the data. The java server pages contain HTML, XML and Java Script, like a normal HTML site. Futhermore you can use java code. Struts provide tag libraries, a summary of functions, which can be use to prepare the data for displaying.</p> <p class="ttext-western">The last component is the controller. The controller manage the request of the web browser, which a user called by an address (URL). But also forward to an action which are execute and which dialogs will be used to display the informations.</p> <p class="ttext-western">The picture below illustrates the interaction between these components.</p> <p class="ttext-western"><img src="http://www.laliluna.de/assets/images/tutorials/what-is-struts/struts-workflow.gif" alt="" /><br /> <br /> </p> <p class="ttext-western">If the user sends a query with a browser, the controller(servlet) gets and processes this query. It decides which action will be called or to which view component it must be forward.</p> <p class="ttext-western">After the controller calls an action, the action can read data from a database and provide this data to the model component, java beans. The action (business logic) returns the "next step" to the controller. The controller checks what kind is the next step. (JSP View, next action, ...) and forwards to it.</p> <p class="ttext-western">The view component (JSP) reads the updated data from the model component and prepare this for the presentation. Then it sends the answer as HTML site back to the browser. The user sees the result of his query. </p> <strong>Struts configuration</strong> <p class="ttext-western">Struts will be configured with various configuration files. The following files are very important.</p> <p class="ttext-western">web.xml</p> <p class="ttext-western">struts-config.xml</p> <p class="ttext-western">Struts-Tag-Bibliotheken</p> <p class="ttext-western">Properties-Dateien</p> <p class="ttext-western">The illustration will show you, on which places struts use the configuration files.</p> <p class="ttext-western"><img src="http://www.laliluna.de/assets/images/tutorials/what-is-struts/configfiles-diagram.gif" alt="" /><br /> <br /> </p> <p class="ttext-western"><strong>web.xml</strong></p> <p class="ttext-western">With the web.xml you configure the web server for the struts application. In this file you can set where the web server find the struts-config.xml and some other global properties.</p> <p class="ttext-western"><strong>struts-config.xml</strong></p> <p class="ttext-western">The controller calls the business logic or a view with a name. The allocation of the names to the action classes or JSP Files(Views) will be set in the struts-config.xml. The advantage is that you can change the definition of the Workflows (Action Mapping), without using the long class names everytime. If you change a class name, you only have to change the name in the struts-config.xml. You don´t update any other part of your application.</p> <p class="ttext-western"><strong>Struts-Tag-Libraries</strong></p> <p class="ttext-western">The Struts-Tag-Libraries, a summary of functions, extends the functionality of JavaServer pages. They support the internationalisation (multi-language) of your web application, and the easy creation of form elements.</p> <p class="ttext-western"><strong>Properties files</strong></p> <p class="ttext-western">This files will be used to keep the internationalized textes of your web application. You can create a seperated properties file for each language, which contain all textes of the application.</p> <p lang="de-DE">杞嚜錛歨ttp://www.laliluna.de<br /> </p> <img src ="http://m.tkk7.com/ec2008/aggbug/144656.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/ec2008/" target="_blank">鏈堣娊鍎?/a> 2007-09-12 23:58 <a href="http://m.tkk7.com/ec2008/archive/2007/09/12/144656.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Hibernate瀵硅薄鐨勪笁縐嶇姸鎬?/title><link>http://m.tkk7.com/ec2008/archive/2007/09/12/144572.html</link><dc:creator>鏈堣娊鍎?/dc:creator><author>鏈堣娊鍎?/author><pubDate>Wed, 12 Sep 2007 09:58:00 GMT</pubDate><guid>http://m.tkk7.com/ec2008/archive/2007/09/12/144572.html</guid><wfw:comment>http://m.tkk7.com/ec2008/comments/144572.html</wfw:comment><comments>http://m.tkk7.com/ec2008/archive/2007/09/12/144572.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/ec2008/comments/commentRss/144572.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/ec2008/services/trackbacks/144572.html</trackback:ping><description><![CDATA[<p><font style="font-size: 14px;" face="Courier New">Hibernate鐨勫璞℃湁3縐嶇姸鎬?鍒嗗埆涓?鐬椂鎬?Transient)銆佹寔涔呮?Persistent)銆佽劚綆℃?Detached).澶勪簬鎸佷箙鎬佺殑瀵硅薄涔熺О涓篜O(PersistenceObject),鐬椂瀵硅薄鍜岃劚綆″璞′篃縐頒負VO(ValueObject).</font></p> <p><font style="font-size: 14px;" face="Courier New"><strong>鐬椂鎬?/strong><br /> 鐢眓ew鍛戒護寮杈熷唴瀛樼┖闂寸殑java瀵硅薄,</font></p> <div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 0);">eg.Person person</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">new Person(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">xiaoxiao</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">濂?/span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);</span></div> <p><font style="font-size: 14px;" face="Courier New">濡傛灉娌℃湁鍙橀噺瀵硅瀵硅薄榪涜寮曠敤,瀹冨皢琚玧ava铏氭嫙鏈哄洖鏀?</font></p> <p><font style="font-size: 14px;" face="Courier New">鐬椂瀵硅薄鍦ㄥ唴瀛樺绔嬪瓨鍦?瀹冩槸鎼哄甫淇℃伅鐨勮澆浣?涓嶅拰鏁版嵁搴撶殑鏁版嵁鏈変換浣曞叧鑱斿叧緋?鍦℉ibernate涓?鍙氳繃session鐨剆ave()鎴杝aveOrUpdate()鏂規硶灝嗙灛鏃跺璞′笌鏁版嵁搴撶浉鍏寵仈,騫跺皢鏁版嵁瀵瑰簲鐨勬彃鍏ユ暟鎹簱涓?姝ゆ椂璇ョ灛鏃跺璞¤漿鍙樻垚鎸佷箙鍖栧璞?</font></p> <p><font style="font-size: 14px;" face="Courier New"><strong>鎸佷箙鎬?/strong><br /> 澶勪簬璇ョ姸鎬佺殑瀵硅薄鍦ㄦ暟鎹簱涓叿鏈夊搴旂殑璁板綍,騫舵嫢鏈変竴涓寔涔呭寲鏍囪瘑.濡傛灉鏄敤hibernate鐨刣elete()鏂規硶,瀵瑰簲鐨勬寔涔呭璞″氨鍙樻垚鐬椂瀵硅薄,鍥犳暟鎹簱涓殑瀵瑰簲鏁版嵁宸茶鍒犻櫎,璇ュ璞′笉鍐嶄笌鏁版嵁搴撶殑璁板綍鍏寵仈.</font></p> <p><font style="font-size: 14px;" face="Courier New">褰撲竴涓猻ession鎵цclose()鎴朿lear()銆乪vict()涔嬪悗,鎸佷箙瀵硅薄鍙樻垚鑴辯瀵硅薄,姝ゆ椂鎸佷箙瀵硅薄浼氬彉鎴愯劚綆″璞?姝ゆ椂璇ュ璞¤櫧鐒跺叿鏈夋暟鎹簱璇嗗埆鍊?浣嗗畠宸蹭笉鍦℉Ibernate鎸佷箙灞傜殑綆$悊涔嬩笅.</font></p> <p><font style="font-size: 14px;" face="Courier New">鎸佷箙瀵硅薄鍏鋒湁濡備笅鐗圭偣:</font></p> <p><font style="font-size: 14px;" face="Courier New">1.鍜宻ession瀹炰緥鍏寵仈;</font></p> <p><font style="font-size: 14px;" face="Courier New">2.鍦ㄦ暟鎹簱涓湁涓庝箣鍏寵仈鐨勮褰?</font></p> <p><font style="font-size: 14px;" face="Courier New"><strong>鑴辯鎬?br /> </strong>褰撲笌鏌愭寔涔呭璞″叧鑱旂殑session琚叧闂悗,璇ユ寔涔呭璞¤漿鍙樹負鑴辯瀵硅薄.褰撹劚綆″璞¤閲嶆柊鍏寵仈鍒皊ession涓婃椂,騫跺啀嬈¤漿鍙樻垚鎸佷箙瀵硅薄.</font></p> <p><font style="font-size: 14px;" face="Courier New">鑴辯瀵硅薄鎷ユ湁鏁版嵁搴撶殑璇嗗埆鍊?鍙氳繃update()銆乻aveOrUpdate()絳夋柟娉?杞彉鎴愭寔涔呭璞?</font></p> <p><font style="font-size: 14px;" face="Courier New">鑴辯瀵硅薄鍏鋒湁濡備笅鐗圭偣:</font></p> <p><font style="font-size: 14px;" face="Courier New">1.鏈川涓婁笌鐬椂瀵硅薄鐩稿悓,鍦ㄦ病鏈変換浣曞彉閲忓紩鐢ㄥ畠鏃?JVM浼氬湪閫傚綋鐨勬椂鍊欏皢瀹冨洖鏀?</font></p> <p><font style="font-size: 14px;" face="Courier New">2.姣旂灛鏃跺璞″浜嗕竴涓暟鎹簱璁板綍鏍囪瘑鍊?<br /> </font></p> <br /> <br /> <p id="TBPingURL">銆婅漿銆?/p> <img src ="http://m.tkk7.com/ec2008/aggbug/144572.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/ec2008/" target="_blank">鏈堣娊鍎?/a> 2007-09-12 17:58 <a href="http://m.tkk7.com/ec2008/archive/2007/09/12/144572.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Generic Data Access Objects涓綃囧叧浜庢硾鍨婦AO鐨勬枃绔?/title><link>http://m.tkk7.com/ec2008/archive/2007/09/12/144529.html</link><dc:creator>鏈堣娊鍎?/dc:creator><author>鏈堣娊鍎?/author><pubDate>Wed, 12 Sep 2007 08:22:00 GMT</pubDate><guid>http://m.tkk7.com/ec2008/archive/2007/09/12/144529.html</guid><wfw:comment>http://m.tkk7.com/ec2008/comments/144529.html</wfw:comment><comments>http://m.tkk7.com/ec2008/archive/2007/09/12/144529.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/ec2008/comments/commentRss/144529.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/ec2008/services/trackbacks/144529.html</trackback:ping><description><![CDATA[<p>This is a pattern for Data Access Objects with JDK 5.0, from the <a _base_>CaveatEmptor</a> example application. It is also explained in the book <a _base_>Java Persistence with Hibernate</a>. Two links you might find useful: <a _base_>Sessions and transactions</a> and <a _base_>Open Session in View</a>.</p> <p>This time I based the DAO example on interfaces. Tools like Hibernate already provide database portability, so persistence layer portability shouldn't be a driving motivation for interfaces. However, DAO interfaces make sense in more complex applications, when several persistence services are encapsulate in one persistence layer. I'd say that you should use Hibernate (or Java Persistence APIs) directly in most cases, the best reason to use an additional DAO layer is higher abstraction (e.g. methods like <tt>getMaximumBid()</tt> instead of <tt>session.createQuery(...)</tt> repeated a dozen times).</p> <h2>The DAO interfaces</h2> <p>I use one interface per persistent entity, with a super interface for common CRUDfunctionality:</p> <div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">interface</span><span style="color: rgb(0, 0, 0);"> GenericDAO</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">T, ID </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> Serializable</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> {<br /> <br />     T findById(ID id, </span><span style="color: rgb(0, 0, 255);">boolean</span><span style="color: rgb(0, 0, 0);"> lock);<br /> <br />     List</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">T</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> findAll();<br /> <br />     List</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">T</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> findByExample(T exampleInstance);<br /> <br />     T makePersistent(T entity);<br /> <br />     </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> makeTransient(T entity);<br /> }</span></div> <br /> You can already see that this is going to be a pattern for a state-oriented data access API, with methods such as <tt>makePersistent()</tt> and <tt>makeTransient()</tt>. Furthermore, to implement a DAO you have to provide a type and an identifier argument. As for most ORM solutions, identifier types have to be serializable. <p>The DAO interface for a particular entity extends the generic interface and provides the type arguments:</p> <br /> <div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">interface</span><span style="color: rgb(0, 0, 0);"> ItemDAO </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> GenericDAO</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">Item, Long</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> {<br /> <br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">final</span><span style="color: rgb(0, 0, 0);"> String QUERY_MAXBID </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">ItemDAO.QUERY_MAXBID</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">final</span><span style="color: rgb(0, 0, 0);"> String QUERY_MINBID </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">ItemDAO.QUERY_MINBID</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br /> <br />     Bid getMaxBid(Long itemId);<br />     Bid getMinBid(Long itemId);<br /> <br /> }</span></div> <br /> <p>We basically separate generic CRUD operations and actual business-related data access operations from each other. (Ignore the named query constants for now, they are convenient if you use annotations.) However, even if only CRUD operations are needed for a particular entity, you should still write an interface for it, even it it is going to be empty. It is important to use a concrete DAO in your controller code, otherwise you will face some refactoring once you have to introduce specific data access operations for this entity.</p> <a style="width: 20px; height: 20px; text-indent: 20px; background-repeat: no-repeat; background-image: url(/CuteSoft_Client/CuteEditor/Load.ashx?type=image&file=anchor.gif);" name="A3" _base_></a> <h2>An implementation with Hibernate</h2> <p>An implementation of the interfaces could be done with any state-management capable persistence service. First, the generic CRUD implementation with Hibernate:</p> <div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">abstract</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> GenericHibernateDAO</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">T, ID </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> Serializable</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />         </span><span style="color: rgb(0, 0, 255);">implements</span><span style="color: rgb(0, 0, 0);"> GenericDAO</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">T, ID</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> {<br /> <br />     </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> Class</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">T</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> persistentClass;<br />     </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> Session session;<br /> <br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> GenericHibernateDAO() {<br />         </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.persistentClass </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (Class</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">T</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);">) ((ParameterizedType) getClass()<br />                                 .getGenericSuperclass()).getActualTypeArguments()[</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">];<br />      }<br /> <br />     @SuppressWarnings(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">unchecked</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)<br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> setSession(Session s) {<br />         </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.session </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> s;<br />     }<br /> <br />     </span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"> Session getSession() {<br />         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (session </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">)<br />             </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> IllegalStateException(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Session has not been set on DAO before usage</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> session;<br />     }<br /> <br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> Class</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">T</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> getPersistentClass() {<br />         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> persistentClass;<br />     }<br /> <br />     @SuppressWarnings(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">unchecked</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)<br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> T findById(ID id, </span><span style="color: rgb(0, 0, 255);">boolean</span><span style="color: rgb(0, 0, 0);"> lock) {<br />         T entity;<br />         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (lock)<br />             entity </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (T) getSession().load(getPersistentClass(), id, LockMode.UPGRADE);<br />         </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />             entity </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (T) getSession().load(getPersistentClass(), id);<br /> <br />         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> entity;<br />     }<br /> <br />     @SuppressWarnings(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">unchecked</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)<br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> List</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">T</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> findAll() {<br />         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> findByCriteria();<br />     }<br /> <br />     @SuppressWarnings(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">unchecked</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)<br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> List</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">T</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> findByExample(T exampleInstance, String[] excludeProperty) {<br />         Criteria crit </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> getSession().createCriteria(getPersistentClass());<br />         Example example </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">  Example.create(exampleInstance);<br />         </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> (String exclude : excludeProperty) {<br />             example.excludeProperty(exclude);<br />         }<br />         crit.add(example);<br />         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> crit.list();<br />     }<br /> <br />     @SuppressWarnings(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">unchecked</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)<br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> T makePersistent(T entity) {<br />         getSession().saveOrUpdate(entity);<br />         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> entity;<br />     }<br /> <br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> makeTransient(T entity) {<br />         getSession().delete(entity);<br />     }<br /> <br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> flush() {<br />         getSession().flush();<br />     }<br /> <br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> clear() {<br />         getSession().clear();<br />     }<br /> <br />     </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />      * Use this inside subclasses as a convenience method.<br />      </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />     @SuppressWarnings(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">unchecked</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)<br />     </span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"> List</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">T</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> findByCriteria(Criterion<img src="http://m.tkk7.com/Images/dot.gif" alt="" /> criterion) {<br />         Criteria crit </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> getSession().createCriteria(getPersistentClass());<br />         </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> (Criterion c : criterion) {<br />             crit.add(c);<br />         }<br />         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> crit.list();<br />    }<br /> <br /> }</span></div> <p>There are some interesting things in this implementation. First, it clearly needs a <tt>Session</tt> to work, provided with setter injection. You could also use constructor injection. How you set the <tt>Session</tt> and what scope this <tt>Session</tt> has is of no concern to the actual DAO implementation. A DAO should not control transactions or the <tt>Session</tt> scope. </p> <p>We need to suppress a few compile-time warnings about unchecked casts, because Hibernate's interfaces are JDK 1.4 only. What follows are the implementations of the generic CRUD operations, quite straightforward. The last method is quite nice, using another JDK 5.0 feature, <em>varargs</em>. It helps us to build <tt>Criteria</tt> queries in concrete entity DAOs. This is an example of a concrete DAO that extends the generic DAO implementation for Hibernate:</p> <div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> ItemDAOHibernate<br />         </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);">     GenericHibernateDAO</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">Item, Long</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />         </span><span style="color: rgb(0, 0, 255);">implements</span><span style="color: rgb(0, 0, 0);">  ItemDAO {<br /> <br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> Bid getMaxBid(Long itemId) {<br />         Query q </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> getSession().getNamedQuery(ItemDAO.QUERY_MAXBID);<br />         q.setParameter(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">itemid</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, itemId);<br />         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> (Bid) q.uniqueResult();<br />     }<br /> <br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> Bid getMinBid(Long itemId) {<br />         Query q </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> getSession().getNamedQuery(ItemDAO.QUERY_MINBID);<br />         q.setParameter(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">itemid</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, itemId);<br />         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> (Bid) q.uniqueResult();<br />     }<br /> <br /> }</span></div> Another example which uses the <tt>findByCriteria()</tt> method of the superclass with variable arguments: <div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> CategoryDAOHibernate<br />         </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);">     GenericHibernateDAO</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">Category, Long</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />         </span><span style="color: rgb(0, 0, 255);">implements</span><span style="color: rgb(0, 0, 0);">  CategoryDAO {<br /> <br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> Collection</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">Category</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> findAll(</span><span style="color: rgb(0, 0, 255);">boolean</span><span style="color: rgb(0, 0, 0);"> onlyRootCategories) {<br />         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (onlyRootCategories)<br />             </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> findByCriteria( Expression.isNull(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">parent</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">) );<br />         </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />             </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> findAll();<br />     }<br /> }</span></div> <br /> <h2>Preparing DAOs with factories</h2> <p>We could bring it all together in a DAO factory, which not only sets the <tt>Session</tt> when a DAO is constructed but also contains nested classes to implement CRUD-only DAOs with no business-related operations:</p> <br /> <div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> HibernateDAOFactory </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> DAOFactory {<br /> <br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> ItemDAO getItemDAO() {<br />         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> (ItemDAO)instantiateDAO(ItemDAOHibernate.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />     }<br /> <br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> CategoryDAO getCategoryDAO() {<br />         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> (CategoryDAO)instantiateDAO(CategoryDAOHibernate.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />     }<br /> <br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> CommentDAO getCommentDAO() {<br />         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> (CommentDAO)instantiateDAO(CommentDAOHibernate.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />     }<br /> <br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> ShipmentDAO getShipmentDAO() {<br />         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> (ShipmentDAO)instantiateDAO(ShipmentDAOHibernate.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />     }<br /> <br />     </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> GenericHibernateDAO instantiateDAO(Class daoClass) {<br />         </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br />             GenericHibernateDAO dao </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (GenericHibernateDAO)daoClass.newInstance();<br />             dao.setSession(getCurrentSession());<br />             </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> dao;<br />         } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (Exception ex) {<br />             </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> RuntimeException(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Can not instantiate DAO: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> daoClass, ex);<br />         }<br />     }<br /> <br />     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> You could override this if you don't want HibernateUtil for lookup</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"> Session getCurrentSession() {<br />         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> HibernateUtil.getSessionFactory().getCurrentSession();<br />     }<br /> <br />     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Inline concrete DAO implementations with no business-related data access methods.<br />     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> If we use public static nested classes, we can centralize all of them in one source file.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);"><br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> CommentDAOHibernate<br />             </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> GenericHibernateDAO</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">Comment, Long</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />             </span><span style="color: rgb(0, 0, 255);">implements</span><span style="color: rgb(0, 0, 0);"> CommentDAO {}<br /> <br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> ShipmentDAOHibernate<br />             </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> GenericHibernateDAO</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">Shipment, Long</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />             </span><span style="color: rgb(0, 0, 255);">implements</span><span style="color: rgb(0, 0, 0);"> ShipmentDAO {}<br /> <br /> }</span></div> This concrete factory for Hibernate DAOs extends the abstract factory, which is the interface we'll use in application code: <div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">abstract</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> DAOFactory {<br /> <br />     </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />      * Creates a standalone DAOFactory that returns unmanaged DAO<br />      * beans for use in any environment Hibernate has been configured<br />      * for. Uses HibernateUtil/SessionFactory and Hibernate context<br />      * propagation (CurrentSessionContext), thread-bound or transaction-bound,<br />      * and transaction scoped.<br />      </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">final</span><span style="color: rgb(0, 0, 0);"> Class HIBERNATE </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> org.hibernate.ce.auction.dao.hibernate.HibernateDAOFactory.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">;<br /> <br />     </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />      * Factory method for instantiation of concrete factories.<br />      </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> DAOFactory instance(Class factory) {<br />         </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br />             </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> (DAOFactory)factory.newInstance();<br />         } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (Exception ex) {<br />             </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> RuntimeException(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Couldn't create DAOFactory: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> factory);<br />         }<br />     }<br /> <br />     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Add your DAO interfaces here</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">abstract</span><span style="color: rgb(0, 0, 0);"> ItemDAO getItemDAO();<br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">abstract</span><span style="color: rgb(0, 0, 0);"> CategoryDAO getCategoryDAO();<br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">abstract</span><span style="color: rgb(0, 0, 0);"> CommentDAO getCommentDAO();<br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">abstract</span><span style="color: rgb(0, 0, 0);"> ShipmentDAO getShipmentDAO();<br /> <br /> }</span></div> <br /> <p>Note that this factory example is suitable for persistence layers which are primarily implemented with a single persistence service, such as Hibernate or EJB 3.0 persistence. If you have to mix persistence APIs, for example, Hibernate and plain JDBC, the pattern changes slightly. Keep in mind that you can also call <tt>session.connection()</tt> <em>inside</em> a Hibernate-specific DAO, or use one of the many bulk operation/SQL support options in Hibernate 3.1 to avoid plain JDBC.</p> <p>Finally, this is how data access now looks like in controller/command handler code (pick whatever transaction demarcation strategy you like, the DAO code doesn't change):</p> <br /> <div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> EJB3 CMT: @TransactionAttribute(TransactionAttributeType.REQUIRED)</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> execute() {<br /> <br />     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> JTA: UserTransaction utx = jndiContext.lookup("UserTransaction");<br />     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> JTA: utx.begin();<br /> <br />     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Plain JDBC: HibernateUtil.getCurrentSession().beginTransaction();</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);"><br />     DAOFactory factory </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> DAOFactory.instance(DAOFactory.HIBERNATE);<br />     ItemDAO itemDAO </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> factory.getItemDAO();<br />     UserDAO userDAO </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> factory.getUserDAO();<br /> <br />     Bid currentMaxBid </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> itemDAO.getMaxBid(itemId);<br />     Bid currentMinBid </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> itemDAO.getMinBid(itemId);<br /> <br />     Item item </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> itemDAO.findById(itemId, </span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">);<br /> <br />     newBid </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> item.placeBid(userDAO.findById(userId, </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">),<br />                             bidAmount,<br />                             currentMaxBid,<br />                             currentMinBid);<br /> <br />     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> JTA: utx.commit(); </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Don't forget exception handling<br /> <br />     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Plain JDBC: HibernateUtil.getCurrentSession().getTransaction().commit(); </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Don't forget exception handling</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> }</span></div> The database transaction, either JTA or direct JDBC, is started and committed in an interceptor that runs for every <tt>execute()</tt>, following the <a _base_>Open Session in View</a> pattern. You can use AOP for this or any kind of interceptor that can be wrapped around a method call, see <a _base_>Session handling with AOP</a>. <p>鍑鴻嚜錛歨ttp://www.hibernate.org<br /> </p> <p><br /> </p> <p><br /> </p> <img src ="http://m.tkk7.com/ec2008/aggbug/144529.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/ec2008/" target="_blank">鏈堣娊鍎?/a> 2007-09-12 16:22 <a href="http://m.tkk7.com/ec2008/archive/2007/09/12/144529.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://m.tkk7.com/" title="亚洲av成人片在线观看">亚洲av成人片在线观看</a> <div class="friend-links"> </div> </div> </footer> 主站蜘蛛池模板: <a href="http://8888kkk.com" target="_blank">中文字幕不卡免费高清视频</a>| <a href="http://fanqi5.com" target="_blank">亚洲视频精品在线</a>| <a href="http://wwwav800.com" target="_blank">亚洲真人日本在线</a>| <a href="http://hwafarda.com" target="_blank">亚洲自偷自偷在线制服</a>| <a href="http://kelingdq.com" target="_blank">亚洲av无码一区二区乱子伦as</a>| <a href="http://bii59.com" target="_blank">毛片a级毛片免费观看品善网</a>| <a href="http://hkcp168.com" target="_blank">狼友av永久网站免费观看</a>| <a href="http://cangtuyuan.com" target="_blank">免费爱爱的视频太爽了 </a>| <a href="http://222222se.com" target="_blank">国产成人综合亚洲绿色</a>| <a href="http://yy468.com" target="_blank">国产精品九九久久免费视频</a>| <a href="http://tqdrhj.com" target="_blank">中文字幕视频免费</a>| <a href="http://yqstickers.com" target="_blank">成人午夜18免费看</a>| <a href="http://jcthbank.com" target="_blank">亚洲韩国精品无码一区二区三区 </a>| <a href="http://kutuwo.com" target="_blank">亚欧免费无码aⅴ在线观看</a>| <a href="http://222dv.com" target="_blank">好先生在线观看免费播放</a>| <a href="http://linmh.com" target="_blank">中文字幕亚洲不卡在线亚瑟</a>| <a href="http://seosuanfa.com" target="_blank">亚洲网站在线播放</a>| <a href="http://564ka.com" target="_blank">成人片黄网站色大片免费观看cn</a>| <a href="http://caobi97.com" target="_blank">日韩精品无码一区二区三区免费 </a>| <a href="http://njyadi.com" target="_blank">在线看片免费人成视频福利</a>| <a href="http://szicon.com" target="_blank">在线观看国产情趣免费视频</a>| <a href="http://9hao66.com" target="_blank">亚洲一区二区在线视频</a>| <a href="http://yunyitai.com" target="_blank">国产亚洲蜜芽精品久久</a>| <a href="http://ri9999.com" target="_blank">免费a级毛片无码a∨蜜芽试看</a>| <a href="http://cqshangshu.com" target="_blank">亚洲成AⅤ人影院在线观看</a>| <a href="http://nmgqsyg.com" target="_blank">亚洲五月丁香综合视频</a>| <a href="http://taoh2517.com" target="_blank">亚洲第一成年人网站</a>| <a href="http://chiguigu.com" target="_blank">久久久久免费视频</a>| <a href="http://ac839.com" target="_blank">日本xxwwxxww在线视频免费</a>| <a href="http://snsdtv.com" target="_blank">亚洲综合伊人制服丝袜美腿</a>| <a href="http://jcthbank.com" target="_blank">免费萌白酱国产一区二区三区 </a>| <a href="http://952268.com" target="_blank">福利免费观看午夜体检区</a>| <a href="http://cg-fun.com" target="_blank">久久亚洲日韩精品一区二区三区</a>| <a href="http://wo93xyz.com" target="_blank">深夜福利在线视频免费</a>| <a href="http://by4471.com" target="_blank">全部免费毛片在线</a>| <a href="http://zgxxx.com" target="_blank">国产青草亚洲香蕉精品久久 </a>| <a href="http://zg8k.com" target="_blank">亚洲国产成人久久综合野外</a>| <a href="http://fsrongxing.com" target="_blank">亚洲乱码av中文一区二区</a>| <a href="http://2h6m.com" target="_blank">午夜国产精品免费观看 </a>| <a href="http://avyjj.com" target="_blank">最好免费观看韩国+日本</a>| <a href="http://yy885.com" target="_blank">91在线亚洲综合在线</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>