锘??xml version="1.0" encoding="utf-8" standalone="yes"?>老司机亚洲精品影视www,国产亚洲精品拍拍拍拍拍,亚洲精华国产精华精华液http://www.tkk7.com/cherishchen/category/23923.htmlzh-cnWed, 12 May 2010 02:35:11 GMTWed, 12 May 2010 02:35:11 GMT60鍏充簬Java String鐨刬ntern and ==鐨勭瑪璇曢錛屾病鏈夊叏絳斿http://www.tkk7.com/cherishchen/archive/2008/03/17/186782.html鍑爮瑙傛搗鍑爮瑙傛搗Mon, 17 Mar 2008 07:43:00 GMThttp://www.tkk7.com/cherishchen/archive/2008/03/17/186782.htmlhttp://www.tkk7.com/cherishchen/comments/186782.htmlhttp://www.tkk7.com/cherishchen/archive/2008/03/17/186782.html#Feedback0http://www.tkk7.com/cherishchen/comments/commentRss/186782.htmlhttp://www.tkk7.com/cherishchen/services/trackbacks/186782.html
package testPackage;
class Test {
public static void main(String[] args) {
String hello = "Hello", lo = "lo";
System.out.print((hello == "Hello") + " ");
System.out.print((Other.hello == hello) + " ");
System.out.print((other.Other.hello == hello) + " ");
System.out.print((hello == ("Hel"+"lo")) + " ");
System.out.print((hello == ("Hel"+lo)) + " ");
System.out.println(hello == ("Hel"+lo).intern());
}
}
class Other { static String hello = "Hello"; }

       

        and the compilation unit:

package other;
public class Other { static String hello = "Hello"; }
 姝g‘絳旀錛歵rue true true true false true
 

This example illustrates six points:

  • Literal strings within the same class (§8) in the same package (§7) represent references to the same String object (§4.3.1).
  • Literal strings within different classes in the same package represent references to the same String object.
  • Literal strings within different classes in different packages likewise represent references to the same String object.
  • Strings computed by constant expressions (§15.28) are computed at compile time and then treated as if they were literals.
  • Strings computed at run time are newly created and therefore distinct.
  • The result of explicitly interning a computed string is the same string as any pre-existing literal string with the same contents.

 

鍛靛懙錛屾垜鏄病鏈夎兘澶熷叏閮ㄧ瓟瀵?/p>

 

鍙﹀涓綃囧叧浜嶴tring intern鐨勬枃绔狅細(xì)

http://laiseeme.javaeye.com/blog/102442



]]>
璁捐鍙?qiáng)璁捐妯″紡锛?xì)鍏充簬Java鏉冮檺鎺у埗綆楁硶(杞級http://www.tkk7.com/cherishchen/archive/2008/02/25/181882.html鍑爮瑙傛搗鍑爮瑙傛搗Mon, 25 Feb 2008 01:20:00 GMThttp://www.tkk7.com/cherishchen/archive/2008/02/25/181882.htmlhttp://www.tkk7.com/cherishchen/comments/181882.htmlhttp://www.tkk7.com/cherishchen/archive/2008/02/25/181882.html#Feedback0http://www.tkk7.com/cherishchen/comments/commentRss/181882.htmlhttp://www.tkk7.com/cherishchen/services/trackbacks/181882.htmlhttp://publish.itpub.net/j/2008-01-24/200801240919412.shtml

浣滆咃細(xì)鏉ヨ嚜ITPUB璁哄潧  2008-01-24


鍚戝ぇ瀹朵粙緇嶄竴縐嶅緢涓嶉敊錛屼篃鏄疞inux涓殑鏉冮檺綆$悊綆楁硶銆?

銆銆瀹氫箟a^b涓猴細(xì)a鐨刡嬈℃柟

銆銆鍋囧錛屾垜浠負(fù)姣忎竴涓搷浣滆瀹氫竴涓敮涓鐨勬暣鏁板鹼紝姣斿錛?/p>

銆銆鍒犻櫎A---0

銆銆淇敼A---1

銆銆娣誨姞A---2

銆銆鍒犻櫎B---3

銆銆淇敼B---4

銆銆娣誨姞B---5

銆銆銆傘傘?/p>

銆銆鐞嗚涓婂彲浠ユ湁N涓搷浣滐紝榪欏彇鍐充簬浣犵敤浜庡偍瀛樼敤鎴鋒潈闄愬肩殑鏁版嵁綾誨瀷浜嗐?/p>

銆銆榪欐牱錛屽鏋滅敤鎴鋒湁鏉冮檺錛氭坊鍔燗---2;鍒犻櫎B---3;淇敼B---4

銆銆閭g敤鎴風(fēng)殑鏉冮檺鍊?purview =2^2+2^3+2^4=28錛屼篃灝辨槸2鐨勬潈鐨勫拰浜?/p>

銆銆鍖栨垚浜岃繘鍒跺彲浠ヨ〃紺轟負(fù)11100

銆銆濡傛灉瑕侀獙璇佺敤鎴鋒槸鍚︽湁鍒犻櫎B鐨勬潈闄愶紝灝卞彲浠ラ氳繃浣嶄笌榪愮畻鏉ュ疄鐜般?/p>

銆銆鍦↗ava閲岋紝浣嶄笌榪愮畻榪愮畻絎﹀彿涓?amp;

銆銆鍗蟲槸錛歩nt value = purview &((int)Math.pow(2,3));

銆銆浣犱細(xì)鍙戠幇錛屽綋鐢ㄦ埛鏈夋搷浣滄潈闄愭椂錛岃繍綆楀嚭鏉ョ殑緇撴灉閮戒細(xì)絳変簬榪欎釜鎿嶄綔闇瑕佺殑鏉冮檺鍊?

銆銆鍘熺悊錛?/p>

銆銆浣嶄笌榪愮畻錛岄【鍚嶆濅箟灝辨槸瀵逛綅榪涜涓庤繍綆楋細(xì)

銆銆浠ヤ笂闈㈢殑寮忓瓙涓轟緥錛歱urview & 2^3 涔熷氨鏄28&8

銆銆灝嗗畠浠寲鎴愪簩榪涘埗鏈?/p>

銆銆11100

銆銆& 01000

銆銆-------------------

銆銆01000 == 8(鍗佽繘鍒?銆==銆2^3

銆銆鍚岀悊錛屽鏋滆楠岃瘉鏄惁鏈夊垹闄---0鐨勬潈闄?/p>

銆銆鍙互鐢細(xì)purview &((int)Math.pow(2,0));

銆銆鍗籌細(xì)

銆銆11100

銆銆& 00001

銆銆------------------------

銆銆00000 == 0(鍗佽繘鍒?銆銆!=銆2^0

銆銆榪欑綆楁硶鐨勪竴涓紭鐐規(guī)槸閫熷害蹇傚彲浠ュ悓鏃跺鐞哊涓潈闄愶紝璁劇疆N縐嶈鑹?

銆銆濡傛灉鎯抽獙璇佹槸鍚﹀悓鏃舵湁鍒犻櫎A---0鍜屽垹闄---3鐨勬潈闄?/p>

銆銆鍙互鐢╬urview&(2^0+2^3)==(2^0+2^3)?true:false;

銆銆璁劇疆澶氳鑹茬敤鎴楓傛牴鎹潈闄愬煎垽鏂敤鎴風(fēng)殑瑙掕壊銆傘傘?/p>

銆銆涓嬮潰鎻愪緵涓涓猨ava鐨勫崟鎿嶄綔鏉冮檺鍒ゆ柇鐨勪唬鐮侊細(xì)

銆銆//userPurview鏄敤鎴峰叿鏈夌殑鎬繪潈闄?br /> //optPurview鏄竴涓搷浣滆姹傜殑鏉冮檺涓轟竴涓暣鏁?娌℃湁緇忚繃鏉冪殑!)

public static boolean checkPower(int userPurview, int optPurview){
int purviewValue = (int)Math.pow(2, optPurview);
return (userPurview & purviewValue) == purviewValue;
}

銆銆褰撶劧錛屽鏉冮檺鐨勯獙璇佸彧瑕佹墿灞曚竴涓嬪氨鍙互浜嗐?/p>

銆銆鍑犵偣娉ㄦ剰浜嬮」錛氶鍏堬紝涓涓郴緇熷彲鑳芥湁寰堝鐨勬搷浣滐紝鍥犳錛岃寤虹珛鏁版嵁瀛楀吀錛屼互渚挎煡闃咃紝淇敼鏃朵嬌鐢ㄣ傚叾嬈★紝濡傛灉鐢ㄦ暟鎹簱鍌ㄥ瓨鐢ㄦ埛鏉冮檺錛岃娉ㄦ剰鏁板肩殑 鏈夋晥鑼冨洿銆傛搷浣滄潈闄愬艱鐢ㄥ敮涓鐨勬暣鏁?Java鐨刬nt綾誨瀷鏈澶氬彲浠ュ偍瀛?1涓潈闄愬拰.濡傛灉瓚呰繃錛屽彲浠ラ夋嫨鍏跺畠鏁版嵁綾誨瀷錛岃屼笖寤鴻涓嶅悓妯″潡錛屼嬌鐢ㄥ涓潈闄? 鍙橀噺.

 



]]>
java鍩虹錛歜yte涓巌nthttp://www.tkk7.com/cherishchen/archive/2007/07/31/133588.html鍑爮瑙傛搗鍑爮瑙傛搗Tue, 31 Jul 2007 07:54:00 GMThttp://www.tkk7.com/cherishchen/archive/2007/07/31/133588.htmlhttp://www.tkk7.com/cherishchen/comments/133588.htmlhttp://www.tkk7.com/cherishchen/archive/2007/07/31/133588.html#Feedback0http://www.tkk7.com/cherishchen/comments/commentRss/133588.htmlhttp://www.tkk7.com/cherishchen/services/trackbacks/133588.htmlbyte涓巌nt鐨勫尯鍒細(xì)

  • byte uses 1 byte while int uses 4 bytes.
  • integer literals like "45" are of int not byte.If you want a literal to be a byte, you have to cast it: "(byte)45".
  • When values are promoted as part of an expression or as parameters to a method call, they may be promoted to int, but never to byte.
  • Many parts of the Java language used int, but none of them use byte. For example, the length of an array is an int.

byte綾誨瀷鐨勪嬌鐢ㄥ満鍚堬細(xì)

鐢變簬涓嶅悓鐨勬満鍣ㄥ浜?strong>澶氬瓧鑺傛暟鎹?int 灝辨槸閲囩敤4涓猙yte淇濆瓨鏁版嵁錛?/strong>鐨勫瓨鍌ㄦ柟寮忎笉鍚?鍙兘鏄?浣庡瓧鑺傚悜楂樺瓧鑺傚瓨鍌?涔熷彲鑳芥槸浠庨珮瀛楄妭鍚戜綆瀛楄妭瀛樺偍,榪欐牱,鍦?鍒嗘瀽緗戠粶鍗忚鎴栨枃浠舵牸鏃?/strong>,涓轟簡瑙e喅涓嶅悓鏈哄櫒涓婄殑瀛楄妭瀛樺偍欏哄簭闂,鐢╞yte綾誨瀷鏉ヨ〃紺烘暟鎹槸鍚堥傜殑銆?strong>鑰岄氬父鎯呭喌涓?鐢變簬鍏惰〃紺虹殑鏁版嵁鑼冨洿寰堝皬,瀹規(guī)槗閫犳垚婧㈠嚭,搴旈伩鍏嶄嬌鐢ㄣ?/strong>


/**
     * Convert  an int to a byte array
     *
     * @param value int
     * @return byte[]
     */
public static byte[] intToByteArray(int value) {
        byte[] b = new byte[4];

     // 浣跨敤4涓猙yte琛ㄧずint
        for (int i = 0; i < 4; i++) {
            int offset = (b.length - 1 - i) * 8;  // 鍋忕Щ閲?br>            b[i] = (byte) ((value >> offset) & 0xFF); //姣忔鍙?bit
        }
        return b;
    }


    /**
     * Convert the byte array to an int starting from the given offset.
     *
     * @param b The byte array
     * @param offset The array offset,濡傛灉byte鏁扮粍闀垮害灝辨槸4錛屽垯璇ュ間負(fù)0
     * @return The integer
     */  

public static int byteArrayToInt(byte[] b, int offset) {
        int value = 0;
        for (int i = 0; i < b.length; i++) {
            int shift = (b.length - 1 - i) * 8;
            value += (b[i + offset] & 0xFF) << shift;
        }
        return value;
    }

 

public static void main(String[] args) {
        byte[] bb=intToByteArray(255);
        for(int i=0;i<bb.length;i++){
            System.out.println(bb[i]);
        }       
    }

杈撳嚭緇撴灉錛?/p>

0
0
0
-1

榪欐槸琛ョ爜鐨勫艦寮忥紙10000001錛夛紝鍙栧弽鍔?鍙互寰楀埌婧愮爜錛?1111111錛?

]]>
鍒ゆ柇resultset鏄惁鍚湁璁板綍http://www.tkk7.com/cherishchen/archive/2007/07/30/133368.html鍑爮瑙傛搗鍑爮瑙傛搗Mon, 30 Jul 2007 08:42:00 GMThttp://www.tkk7.com/cherishchen/archive/2007/07/30/133368.htmlhttp://www.tkk7.com/cherishchen/comments/133368.htmlhttp://www.tkk7.com/cherishchen/archive/2007/07/30/133368.html#Feedback0http://www.tkk7.com/cherishchen/comments/commentRss/133368.htmlhttp://www.tkk7.com/cherishchen/services/trackbacks/133368.htmlboolean hasRows = false;
while (rs.next()){
  hasRows  = true;
  //Do your stuff
}
if (!hasRows ){
  //Empty result set
}
//You dont have to test for null result set



]]>
java鐨勬暟鎹被鍨嬶紙澶囩敤錛?/title><link>http://www.tkk7.com/cherishchen/archive/2007/07/27/132720.html</link><dc:creator>鍑爮瑙傛搗</dc:creator><author>鍑爮瑙傛搗</author><pubDate>Fri, 27 Jul 2007 03:11:00 GMT</pubDate><guid>http://www.tkk7.com/cherishchen/archive/2007/07/27/132720.html</guid><wfw:comment>http://www.tkk7.com/cherishchen/comments/132720.html</wfw:comment><comments>http://www.tkk7.com/cherishchen/archive/2007/07/27/132720.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/cherishchen/comments/commentRss/132720.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/cherishchen/services/trackbacks/132720.html</trackback:ping><description><![CDATA[  緇撳悎浜嗗墠孌墊椂闂寸湅unicode鐨勭煡璇嗚ˉ琛ュ熀紜<br><br> <ul> <li><strong>byte</strong>: The <code>byte</code> data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The <code>byte</code> data type can be useful for saving memory in large <a >arrays</a>, where the memory savings actually matters. They can also be used in place of <code>int</code> where their limits help to clarify your code; the fact that a variable's range is limited can serve as a form of documentation. </li> <li><strong>short</strong>: The <code>short</code> data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As with <code>byte</code>, the same guidelines apply: you can use a <code>short</code> to save memory in large arrays, in situations where the memory savings actually matters. </li> <li><strong>int</strong>: The <code>int</code> data type is a 32-bit signed two's complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive). For integral values, this data type is generally the default choice unless there is a reason (like the above) to choose something else. This data type will most likely be large enough for the numbers your program will use, but if you need a wider range of values, use <code>long</code> instead. </li> <li><strong>long</strong>: The <code>long</code> data type is a 64-bit signed two's complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). Use this data type when you need a range of values wider than those provided by <code>int</code>. </li> <li><strong>float</strong>: The <code>float</code> data type is a single-precision 32-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in section <a >4.2.3</a> of the Java Language Specification. As with the recommendations for <code>byte</code> and <code>short</code>, use a <code>float</code> (instead of <code>double</code>) if you need to save memory in large arrays of floating point numbers. This data type should never be used for precise values, such as currency. For that, you will need to use the <a >java.math.BigDecimal</a> class instead. <a >Numbers and Strings</a> covers <code>BigDecimal</code> and other useful classes provided by the Java platform. </li> <li><strong>double</strong>: The <code>double</code> data type is a double-precision 64-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in section <a >4.2.3</a> of the Java Language Specification. For decimal values, this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency. </li> <li><strong>boolean</strong>: The <code>boolean</code> data type has only two possible values: <code>true</code> and <code>false</code>. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defined. </li> <li><strong>char</strong>: The <code>char</code> data type is a single 16-bit Unicode character. It has a minimum value of <code>'\u0000'</code> (or 0) and a maximum value of <code>'\uffff'</code> (or 65,535 inclusive). </li> </ul> <p> </p> <table unselectable="on" border="0" cellpadding="2" cellspacing="0" width="828"> <tbody> <tr> <td valign="top" width="173"> <p><strong>綾誨瀷鍚嶇О</strong></p> </td> <td valign="top" width="177"><strong>綾誨瀷瀹氫箟</strong></td> <td valign="top" width="474"><strong>綾誨瀷鍙栧?/strong></td> </tr> <tr> <td valign="top" width="173"><em>boolean</em></td> <td valign="top" width="177">甯冨皵鍊?/td> <td valign="top" width="473"><em>true</em>, <em>false</em></td> </tr> <tr> <td valign="top" width="173"><em>byte</em></td> <td valign="top" width="177">8浣?strong>鏈夌鍙鋒暣鏁?/strong></td> <td valign="top" width="473">鏈灝忓?128錛屾渶澶у?27</td> </tr> <tr> <td valign="top" width="173"><em>short</em></td> <td valign="top" width="177">16浣?strong>鏈夌鍙鋒暣鏁?/strong></td> <td valign="top" width="472"> <p>鏈灝忓?32768錛?2<sup>15</sup>錛夛紝鏈澶у?2767錛?<sup>15</sup>-1錛?/p> </td> </tr> <tr> <td valign="top" width="173"><em>int</em></td> <td valign="top" width="177">32浣?strong>鏈夌鍙鋒暣鏁?/strong></td> <td valign="top" width="472">鏈灝忓?2147483648錛?2<sup>31</sup>錛夛紝鏈澶у?147483647錛?<sup>31</sup>-1錛?/td> </tr> <tr> <td valign="top" width="173"><em>long</em></td> <td valign="top" width="177">64浣?strong>鏈夌鍙鋒暣鏁?/strong></td> <td valign="top" width="472"> <p>-2<sup>63</sup>~(2<sup>63</sup>-1)</p> </td> </tr> <tr> <td valign="top" width="173"><em>float</em></td> <td valign="top" width="177">32浣嶆誕鐐規(guī)暟</td> <td valign="top" width="472"> <p>1.4E-45~3.4028235E38</p> </td> </tr> <tr> <td valign="top" width="173"><em>double</em></td> <td valign="top" width="177">64浣嶆誕鐐規(guī)暟</td> <td valign="top" width="472">4.9E-324~1.7976931348623157E308</td> </tr> <tr> <td valign="top" width="173">char</td> <td valign="top" width="177">16浣峌nicode瀛楃</td> <td valign="top" width="472"> </td> </tr> <tr> <td valign="top" width="173"> </td> <td valign="top" width="177"> </td> <td valign="top" width="472"> </td> </tr> </tbody> </table> <p> </p> <p> </p> <p> </p> <div id="u0eummc" class="ad_in_page"> <script type="text/javascript"><!-- google_ad_client = "pub-7843511305731432"; google_ad_width =" 468; google_ad_height" = 60; google_ad_format =" "468x60_as"; google_ad_type" = "text_image"; //2007-07-22: test google_ad_channel =" "2043099642"; google_color_border" = "ffffff"; google_color_bg =" "ffffff"; google_color_link" = "ffffff"; google_color_text =" "000000"; google_color_url" = "000033"; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div><img src ="http://www.tkk7.com/cherishchen/aggbug/132720.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/cherishchen/" target="_blank">鍑爮瑙傛搗</a> 2007-07-27 11:11 <a href="http://www.tkk7.com/cherishchen/archive/2007/07/27/132720.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>java璇█涓殑bit 縐諱綅鎿嶄綔http://www.tkk7.com/cherishchen/archive/2007/07/27/132717.html鍑爮瑙傛搗鍑爮瑙傛搗Fri, 27 Jul 2007 03:08:00 GMThttp://www.tkk7.com/cherishchen/archive/2007/07/27/132717.htmlhttp://www.tkk7.com/cherishchen/comments/132717.htmlhttp://www.tkk7.com/cherishchen/archive/2007/07/27/132717.html#Feedback0http://www.tkk7.com/cherishchen/comments/commentRss/132717.htmlhttp://www.tkk7.com/cherishchen/services/trackbacks/132717.html
 

java 浣嶆搷浣滅錛?/strong>

鍙栧弽錛?/strong>~x
- flips each bit to the opposite value.

涓庢搷浣滐細(xì)AND

x & y
- AND operation between the corresponding bits in x and y.

鎴栨搷浣滐細(xì)OR
x | y
- OR operation between the corresponding bits in x and y.

寮傛垨鎿嶄綔錛歑OR
x ^ y
- XOR operation between the corresponding bits in x and y.

宸︾Щ鎿嶄綔錛歋hift left
x << y
- shifts x to the left by y bits. The high order bits are lost while zeros fill the right bits.

灝唜宸︾Щy浣嶏紝縐誨姩榪囩▼涓紝楂樹綅浼?xì)涓㈠?

鏈夌鍙鋒暟鍙崇Щ鎿嶄綔錛歋hift Right - Signed
x >> y
- shifts x to the right by y bits. The low order bits are lost while the sign bit value (0 for positive numbers, 1 for negative) fills in the left bits.

鏃犵鍙鋒暟鍙崇Щ錛歋hift Right - Unsigned
x >>> y
- shifts x to the right by y bits. The low order bits are lost while zeros fill in the left bits regardless of the sign.

渚嬪瓙錛?/strong>

涓嬮潰鐨勪緥瀛愭樉紺哄浣曞皢涓涓猧nt鏁扮粍閫氳繃縐諱綅鎿嶄綔鍘嬬緝鍒頒竴涓猧nt鍐呬繚瀛橈紝鍏跺師鐞嗘槸鍦╦ava璇█涓紝int綾誨瀷浣跨敤4 bytes鏉ヤ繚瀛橈紝鍥犳瀵逛簬闇瑕佸帇緙╃殑int鏁扮粍錛屽叾涓殑姣忎竴涓猧nt鍊肩殑澶у皬涓嶈兘瓚呰繃255錛?鐨?嬈℃柟-1錛夛紝鍥犳榪欏彧鏄竴涓疄渚嬶細(xì)

  int [] aRGB = {0x56, 0x78, 0x9A, 0xBC};   // 鏄敤16榪涘埗淇濆瓨鐨?縐嶉鑹插?br>  int color_val = aRGB[3];   
  color_val = color_val | (aRGB[2] << 8);  // 涓轟簡鍘嬬緝錛岄渶瑕佹斁緗埌color_val鍊肩殑絎簩涓瓧鑺備綅緗笂錛氬皢aRGB[2] 宸︾Щ鍒扮浜屼釜byte錛屽悓鏃朵笌color_val榪涜鎴栨搷浣滐紝涓嬮潰鍚岀悊
  color_val = color_val | (aRGB[1] << 16);  
  color_val = color_val | (aRBG[0] << 24);

鎿嶄綔瀹岀殑緇撴灉鏄?6 78 9A BC

濡傛灉瑕佷粠colorVal 榪樺師涓篿nt鏁扮粍錛屾垨鑰呭緱鍒版暟緇勪腑鐨勬煇涓鹼紝鍙渶瑕佸colorVal 榪涜鐩稿簲鐨勫彸縐繪搷浣滃嵆鍙細(xì)

  int alpha_val = (colorVal >>> 24) & 0xFF;
  int red_val   = (colorVal >>> 16) & 0xFF;
  int green_val = (colorVal >>>  8) & 0xFF;
  int blue_val  =  colorVal & 0xFF;

鍙傝冭祫鏂欙細(xì)

Bits in Java



]]>
JPA --Java EE 5.0 ORM 瑙勮寖錛堣漿錛?/title><link>http://www.tkk7.com/cherishchen/archive/2007/07/21/131658.html</link><dc:creator>鍑爮瑙傛搗</dc:creator><author>鍑爮瑙傛搗</author><pubDate>Sat, 21 Jul 2007 12:50:00 GMT</pubDate><guid>http://www.tkk7.com/cherishchen/archive/2007/07/21/131658.html</guid><wfw:comment>http://www.tkk7.com/cherishchen/comments/131658.html</wfw:comment><comments>http://www.tkk7.com/cherishchen/archive/2007/07/21/131658.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.tkk7.com/cherishchen/comments/commentRss/131658.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/cherishchen/services/trackbacks/131658.html</trackback:ping><description><![CDATA[<p>浣滆? 瀹冨北 鍑哄:<a >IT168</a></p> <p><a title="http://tech.it168.com/j/n/2007-03-05/200703051354348.shtml" >http://tech.it168.com/j/n/2007-03-05/200703051354348.shtml</a></p> <p>PA浣滀負(fù)涓欏瑰璞℃寔涔呭寲鐨勬爣鍑嗭紝涓嶄絾鍙互鑾峰緱Java EE搴旂敤鏈嶅姟鍣ㄧ殑鏀寔錛岃繕鍙互鐩存帴鍦↗ava SE涓嬌鐢ㄣ?/p> <p>浠嬬粛寰楀緢娓呮鐨勬枃绔?/p> <p> </p> <p><strong>JPA姒傝堪</strong> <p>JPA(Java Persistence API)浣滀負(fù)Java EE 5.0騫沖彴鏍囧噯鐨凮RM瑙勮寖錛屽皢寰楀埌鎵鏈塉ava EE鏈嶅姟鍣ㄧ殑鏀寔銆係un榪欐鍚稿彇浜嗕箣鍓岴JB瑙勮寖鎯ㄧ棝澶辮觸鐨勭粡鍘嗭紝鍦ㄥ厖鍒嗗惛鏀剁幇鏈塐RM妗嗘灦鐨勫熀紜涓婏紝寰楀埌浜嗕竴涓槗浜庝嬌鐢ㄣ佷幾緙╂у己鐨凮RM瑙勮寖銆備粠鐩墠鐨勫紑鍙戠ぞ鍖虹殑鍙嶅簲涓婄湅錛孞PA鍙楀埌浜嗘瀬澶х殑鏀寔鍜岃禐鎵紝JPA浣滀負(fù)ORM棰嗗煙鏍囧噯鍖栨暣鍚堣呯殑鐩爣搴旇涓嶉毦瀹炵幇銆?nbsp; <p>JPA閫氳繃JDK 5.0娉ㄨВ鎴朮ML鎻忚堪瀵硅薄錛嶅叧緋昏〃鐨勬槧灝勫叧緋伙紝騫跺皢榪愯鏈熺殑瀹炰綋瀵硅薄鎸佷箙鍖栧埌鏁版嵁搴撲腑錛屽浘 1寰堝ソ鍦版弿榪頒簡JPA鐨勭粨鏋勶細(xì) <p><img height="305" alt="" src="http://developer.51cto.com/files/uploadimg/20070305/1547200.JPG" width="450"> <p>Sun寮曞叆鏂扮殑JPA ORM瑙勮寖鍑轟簬涓や釜鍘熷洜錛氬叾涓錛岀畝鍖栫幇鏈塉ava EE鍜孞ava SE搴旂敤鐨勫璞℃寔涔呭寲鐨勫紑鍙戝伐浣滐紱鍏朵簩錛孲un甯屾湜鏁村悎瀵筄RM鎶鏈紝瀹炵幇澶╀笅褰掍竴銆?nbsp; <p>JPA鐢盓JB 3.0杞歡涓撳緇勫紑鍙戯紝浣滀負(fù)JSR-220瀹炵幇鐨勪竴閮ㄥ垎銆備絾瀹冧笉鍥夸簬EJB 3.0錛屼綘鍙互鍦╓eb搴旂敤銆佺敋鑷蟲闈㈠簲鐢ㄤ腑浣跨敤銆侸PA鐨勫畻鏃ㄦ槸涓篜OJO鎻愪緵鎸佷箙鍖栨爣鍑嗚鑼冿紝鐢辨鍙錛岀粡榪囪繖鍑犲勾鐨勫疄璺墊帰绱紝鑳藉鑴辯瀹瑰櫒鐙珛榪愯錛屾柟渚垮紑鍙戝拰嫻嬭瘯鐨勭悊蹇靛凡緇忔繁鍏ヤ漢蹇冧簡銆傜洰鍓岺ibernate 3.2銆乀opLink 10.1.3浠ュ強(qiáng)OpenJpa閮芥彁渚涗簡JPA鐨勫疄鐜般? <p>JPA鐨勬諱綋鎬濇兂鍜岀幇鏈塇ibernate銆乀opLink錛孞DO絳塐RM妗嗘灦澶т綋涓鑷淬傛葷殑鏉ヨ錛孞PA鍖呮嫭浠ヤ笅3鏂歸潰鐨勬妧鏈細(xì)  <ul> <li>ORM鏄犲皠鍏冩暟鎹紝JPA鏀寔XML鍜孞DK 5.0娉ㄨВ涓ょ鍏冩暟鎹殑褰㈠紡錛屽厓鏁版嵁鎻忚堪瀵硅薄鍜岃〃涔嬮棿鐨勬槧灝勫叧緋伙紝妗嗘灦鎹灝嗗疄浣撳璞℃寔涔呭寲鍒版暟鎹簱琛ㄤ腑錛?nbsp; <li>JPA 鐨凙PI錛岀敤鏉ユ搷浣滃疄浣撳璞★紝鎵цCRUD鎿嶄綔錛屾鏋跺湪鍚庡彴鏇挎垜浠畬鎴愭墍鏈夌殑浜嬫儏錛屽紑鍙戣呬粠綣佺悙鐨凧DBC鍜孲QL浠g爜涓В鑴卞嚭鏉ャ?nbsp; <li>鏌ヨ璇█錛岃繖鏄寔涔呭寲鎿嶄綔涓緢閲嶈鐨勪竴涓柟闈紝閫氳繃闈㈠悜瀵硅薄鑰岄潪闈㈠悜鏁版嵁搴撶殑鏌ヨ璇█鏌ヨ鏁版嵁錛岄伩鍏嶇▼搴忕殑SQL璇彞绱у瘑鑰﹀悎銆?nbsp;</li></ul><img src ="http://www.tkk7.com/cherishchen/aggbug/131658.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/cherishchen/" target="_blank">鍑爮瑙傛搗</a> 2007-07-21 20:50 <a href="http://www.tkk7.com/cherishchen/archive/2007/07/21/131658.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>涓涓畝鍗昩log澶囦喚宸ュ叿鐨勫疄鐜?/title><link>http://www.tkk7.com/cherishchen/archive/2007/07/16/130508.html</link><dc:creator>鍑爮瑙傛搗</dc:creator><author>鍑爮瑙傛搗</author><pubDate>Mon, 16 Jul 2007 03:22:00 GMT</pubDate><guid>http://www.tkk7.com/cherishchen/archive/2007/07/16/130508.html</guid><wfw:comment>http://www.tkk7.com/cherishchen/comments/130508.html</wfw:comment><comments>http://www.tkk7.com/cherishchen/archive/2007/07/16/130508.html#Feedback</comments><slash:comments>8</slash:comments><wfw:commentRss>http://www.tkk7.com/cherishchen/comments/commentRss/130508.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/cherishchen/services/trackbacks/130508.html</trackback:ping><description><![CDATA[<p> </p> <p>涓轟簡澶囦喚blog錛岀畝鍗曞啓浜嗕竴涓傜敤浜巄logjava絳塵etaWeblog鐨刡log澶囦喚宸ュ叿錛屽姛鑳斤細(xì)</p> <p>錛?錛夊浠絧ost鐨勬鏂囧埌鏈湴</p> <p>錛?錛夊浠芥鏂囦腑鐨勫浘鐗囥乧ss鏂囦歡鍒版湰鍦?/p> <p>錛?錛夊熀浜庝互涓婁袱鐨勬楠わ紝淇敼鐩稿叧鐨勯摼鎺ワ紝瀹炵幇鏈湴鑴辨満嫻忚</p> <p>鎯沖埌浜嗕絾鏄湭瀹炵幇鐨勫姛鑳斤細(xì)</p> <p>錛?錛夎瘎璁烘棤娉曚繚瀛?/p> <p>錛?錛夊悎閫傜殑璇濆彲浠ヨ冭檻浠clipes RCP褰㈠紡鍖呰</p> <p> </p> <div id="m4wqq2y" class="ad_in_page"> <script type="text/javascript"><!-- google_ad_client = "pub-7843511305731432"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_type = "text_image"; //2007-07-22: test google_ad_channel = "2043099642"; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "FFFFFF"; google_color_text = "000000"; google_color_url = "000033"; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div> <h2>涓銆佸疄鐜板師鐞?/h2> <p>錛?錛夎幏鍙杙ost鐨勬柟娉曪細(xì)浣跨敤MetaWeblog鎻愪緵鐨凙PI鎺ュ彛</p> <p>metaWeblog.getRecentPosts (blogid, username, password, numberOfPosts) returns array of structs,</p> <p>Each struct represents a recent weblog post, containing the same information that a call to metaWeblog.getPost would return. </p> <p>If numberOfPosts is 1, you get the most recent post. If it's 2 you also get the second most recent post, as the second array element. If numberOfPosts is greater than the number of posts in the weblog you get all the posts in the weblog. </p> <p> </p> <p>(2) 浣跨敤姝e垯琛ㄨ揪寮忓垎鏋愯幏鍙栦笅鏉ョ殑post錛岃В鏋愬嚭post涓寘鍚殑css鍜屽浘鐗囨枃浠剁殑鍦板潃錛屾墽琛屼袱姝ユ搷浣?/p> <ul> <li>鏍規(guī)嵁鍦板潃錛屾姄鍙栧浘鐗囦繚瀛樺埌鏈湴 <li>淇敼post涓殑鍦板潃涓烘湰鍦頒繚瀛樺湴鍧 </li></ul> <p>(3) 浣跨敤xml-rpc鏉ョ畝鍖栬繙紼嬭皟鐢ㄨ繃紼嬬殑緙栫▼</p> <p> </p> <h2>浜屻佷富瑕佺殑浠g爜</h2> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #0000ff">public</span><span style="color: #000000"> ArrayList</span><span style="color: #000000"><</span><span style="color: #000000">SimplePost</span><span style="color: #000000">></span><span style="color: #000000"> getAllPosts(String blogID, String name,String password, </span><span style="color: #0000ff">int</span><span style="color: #000000"> num) </span><span style="color: #0000ff">throws</span><span style="color: #000000"> XmlRpcException {<br>        ArrayList</span><span style="color: #000000"><</span><span style="color: #000000">SimplePost</span><span style="color: #000000">></span><span style="color: #000000"> posts </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> ArrayList</span><span style="color: #000000"><</span><span style="color: #000000">SimplePost</span><span style="color: #000000">></span><span style="color: #000000">();<br>        Object[] params </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Object[] { blogID, name, password,</span><span style="color: #0000ff">new</span><span style="color: #000000"> Integer(num) };<br>        Object[] result </span><span style="color: #000000">=</span><span style="color: #000000"> (Object[]) client.execute(</span><span style="color: #000000">"</span><span style="color: #000000">metaWeblog.getRecentPosts</span><span style="color: #000000">"</span><span style="color: #000000">, params);<br><br>        </span><span style="color: #0000ff">for</span><span style="color: #000000"> (</span><span style="color: #0000ff">int</span><span style="color: #000000"> i </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">; i </span><span style="color: #000000"><</span><span style="color: #000000"> result.length; i</span><span style="color: #000000">++</span><span style="color: #000000">) {<br>            Map map </span><span style="color: #000000">=</span><span style="color: #000000"> (Map) result[i];<br>            String postUrl </span><span style="color: #000000">=</span><span style="color: #000000"> (String) map.get(</span><span style="color: #000000">"</span><span style="color: #000000">link</span><span style="color: #000000">"</span><span style="color: #000000">);<br>            String title </span><span style="color: #000000">=</span><span style="color: #000000"> (String) map.get(</span><span style="color: #000000">"</span><span style="color: #000000">title</span><span style="color: #000000">"</span><span style="color: #000000">);<br>            String postId </span><span style="color: #000000">=</span><span style="color: #000000"> (String) map.get(</span><span style="color: #000000">"</span><span style="color: #000000">postid</span><span style="color: #000000">"</span><span style="color: #000000">);<br><br>                        </span><span style="color: #008000">//</span><span style="color: #008000"> post鐨勫唴瀹?/span><span style="color: #008000"><br></span><span style="color: #000000">            String description </span><span style="color: #000000">=</span><span style="color: #000000"> (String) map.get(</span><span style="color: #000000">"</span><span style="color: #000000">description</span><span style="color: #000000">"</span><span style="color: #000000">);<br>            <br>            Map</span><span style="color: #000000"><</span><span style="color: #000000">String, String</span><span style="color: #000000">></span><span style="color: #000000"> images </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> HashMap</span><span style="color: #000000"><</span><span style="color: #000000">String, String</span><span style="color: #000000">></span><span style="color: #000000">();<br>            images </span><span style="color: #000000">=</span><span style="color: #000000"> getImagesURL(description);<br>                    <br>            String newDes </span><span style="color: #000000">=</span><span style="color: #000000"> handleImagesURL(description,postId);            <br>            String descriptioFileName </span><span style="color: #000000">=</span><span style="color: #000000"> savePostContent(savePath, title,postId, newDes, css);<br><br>            SimplePost post </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> SimplePost(postUrl, title, postId,descriptioFileName);<br>            </span><span style="color: #008000">//</span><span style="color: #008000">浠巔ostContent鑾峰彇鍥懼儚鐨勫湴鍧鍜屽悕縐幫紝浠ヤ究鑾峰彇鍥劇墖騫朵繚瀛?/span><span style="color: #008000"><br></span><span style="color: #000000">            post.setImages(images);<br>            posts.add(post);<br>            log.debug(</span><span style="color: #000000">"</span><span style="color: #000000">postID: </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> postId </span><span style="color: #000000">+</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">postTitle :</span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> title);<br>        }<br>        </span><span style="color: #0000ff">return</span><span style="color: #000000"> posts;<br>    }</span></div><br> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> Map</span><span style="color: #000000"><</span><span style="color: #000000">String, String</span><span style="color: #000000">></span><span style="color: #000000"> getImagesURL(String description) {<br><br>       </span><span style="color: #008000"></span><span style="color: #000000">  Map</span><span style="color: #000000"><</span><span style="color: #000000">String, String</span><span style="color: #000000">></span><span style="color: #000000"> map </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> HashMap</span><span style="color: #000000"><</span><span style="color: #000000">String, String</span><span style="color: #000000">></span><span style="color: #000000">();<br>        </span><span style="color: #008000">//</span><span style="color: #008000"> img 鐨勬鍒欒〃杈懼紡<br>      </span><span style="color: #008000"></span><span style="color: #000000">  String imgPattern </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000"><\\s*img\\s+([^>]+)\\s*></span><span style="color: #000000">"</span><span style="color: #000000">;<br>        Pattern p </span><span style="color: #000000">=</span><span style="color: #000000"> Pattern.compile(imgPattern, Pattern.CASE_INSENSITIVE);<br>        Matcher matcher </span><span style="color: #000000">=</span><span style="color: #000000"> p.matcher(description);<br><br>        </span><span style="color: #008000">//</span><span style="color: #008000"> img src鍏冪礌鐨勬鍒欒〃杈懼紡</span><span style="color: #008000"><br></span><span style="color: #000000">        String srcPattern </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">\\s*src\\s*=\\s*\</span><span style="color: #000000">"</span><span style="color: #000000">([</span><span style="color: #000000">^</span><span style="color: #000000">\</span><span style="color: #000000">"</span><span style="color: #000000">]+)\\s*\</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: #008000"></span><span style="color: #000000">  Pattern p2 </span><span style="color: #000000">=</span><span style="color: #000000"> Pattern.compile(srcPattern, Pattern.CASE_INSENSITIVE);<br><br>        </span><span style="color: #0000ff">while</span><span style="color: #000000"> (matcher.find()) {<br>            Matcher matcher2 </span><span style="color: #000000">=</span><span style="color: #000000"> p2.matcher(matcher.group());<br>            </span><span style="color: #008000">//</span><span style="color: #008000"> 涓瀹氳find(),榪欐槸瀹為檯鐨勫尮閰嶅姩浣?/span><span style="color: #008000"><br></span><span style="color: #000000">            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (matcher2.find()) {<br>                String src </span><span style="color: #000000">=</span><span style="color: #000000"> matcher2.group();<br>                log.info(src);<br>                </span><span style="color: #0000ff">int</span><span style="color: #000000"> i2 </span><span style="color: #000000">=</span><span style="color: #000000"> src.lastIndexOf(</span><span style="color: #000000">'</span><span style="color: #000000">/</span><span style="color: #000000">'</span><span style="color: #000000">);<br>                </span><span style="color: #0000ff">int</span><span style="color: #000000"> i1 </span><span style="color: #000000">=</span><span style="color: #000000"> src.indexOf(</span><span style="color: #000000">"</span><span style="color: #000000">http</span><span style="color: #000000">"</span><span style="color: #000000">);<br>                </span><span style="color: #0000ff">if</span><span style="color: #000000"> (i1 </span><span style="color: #000000">!=</span><span style="color: #000000"> </span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">) {<br>                    map.put(src.substring(i2 </span><span style="color: #000000">+</span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000">, src.length() </span><span style="color: #000000">-</span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000">), src<br>                            .substring(i1, src.length() </span><span style="color: #000000">-</span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000">));<br>                }<br>            }<br>        }<br>        log.debug(</span><span style="color: #000000">"</span><span style="color: #000000">鍥劇墖錛?/span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> map);<br>        </span><span style="color: #0000ff">return</span><span style="color: #000000"> map;<br>    }</span></div><br> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #008000">/**</span><span style="color: #008000"><br>     * 鏇挎崲description鐨勫浘鐗囬摼鎺ヤ負(fù)鏈湴鐨勭浉瀵歸摼鎺ワ紝緇撴瀯涓篵logFiles/images/postid/<br>     * <br>     * </span><span style="color: #808080">@param</span><span style="color: #008000"> description<br>     * </span><span style="color: #808080">@param</span><span style="color: #008000"> userName<br>     * </span><span style="color: #808080">@param</span><span style="color: #008000"> postId<br>     * </span><span style="color: #808080">@return</span><span style="color: #008000"><br>     </span><span style="color: #008000">*/</span><span style="color: #000000"><br>    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> String handleImagesURL(String description, String postId) {<br>        String tmp </span><span style="color: #000000">=</span><span style="color: #000000"> description;        <br>        String address</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">images/</span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> postId </span><span style="color: #000000">+</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">/</span><span style="color: #000000">"</span><span style="color: #000000">;<br>        <br>        String imgPattern </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000"><\\s*img\\s+([^>]+)\\s*></span><span style="color: #000000">"</span><span style="color: #000000">;<br>        Pattern p </span><span style="color: #000000">=</span><span style="color: #000000"> Pattern.compile(imgPattern, Pattern.CASE_INSENSITIVE);<br>        Matcher matcher </span><span style="color: #000000">=</span><span style="color: #000000"> p.matcher(tmp);<br><br>        </span><span style="color: #008000">//</span><span style="color: #008000"> img src鍏冪礌鐨勬鍒欒〃杈懼紡</span><span style="color: #008000"><br></span><span style="color: #000000">        String srcPattern </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">\\s*src\\s*=\\s*\</span><span style="color: #000000">"</span><span style="color: #000000">([</span><span style="color: #000000">^</span><span style="color: #000000">\</span><span style="color: #000000">"</span><span style="color: #000000">]+)\\s*\</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: #008000">//</span><span style="color: #008000"> String srcPattern = "\\s*src\\s*=\\s*\'([^\']+)\\s*\'";</span><span style="color: #008000"><br></span><span style="color: #000000">        Pattern p2 </span><span style="color: #000000">=</span><span style="color: #000000"> Pattern.compile(srcPattern, Pattern.CASE_INSENSITIVE);<br>        </span><span style="color: #0000ff">while</span><span style="color: #000000"> (matcher.find()) {<br>            Matcher matcher2 </span><span style="color: #000000">=</span><span style="color: #000000"> p2.matcher(matcher.group());<br>            </span><span style="color: #008000">//</span><span style="color: #008000"> 涓瀹氳find(),榪欐槸瀹為檯鐨勫尮閰嶅姩浣?/span><span style="color: #008000"><br></span><span style="color: #000000">            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (matcher2.find()) {<br>                String src </span><span style="color: #000000">=</span><span style="color: #000000"> matcher2.group();<br>                log.info(src);                <br>                </span><span style="color: #0000ff">int</span><span style="color: #000000"> l2</span><span style="color: #000000">=</span><span style="color: #000000">src.lastIndexOf(</span><span style="color: #000000">'</span><span style="color: #000000">/</span><span style="color: #000000">'</span><span style="color: #000000">)</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">;<br>                log.info(src.substring(l2,src.length()</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">));<br>                tmp</span><span style="color: #000000">=</span><span style="color: #000000">tmp.replace(src,</span><span style="color: #000000">"</span><span style="color: #000000">  src=\</span><span style="color: #000000">""</span><span style="color: #000000">+address+src.substring(l2,src.length()-1)+</span><span style="color: #000000">"</span><span style="color: #000000">\</span><span style="color: #000000">""</span><span style="color: #000000">);                <br>            }<br>        }        <br>        </span><span style="color: #0000ff">return</span><span style="color: #000000"> tmp;<br>    }</span></div><img src ="http://www.tkk7.com/cherishchen/aggbug/130508.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/cherishchen/" target="_blank">鍑爮瑙傛搗</a> 2007-07-16 11:22 <a href="http://www.tkk7.com/cherishchen/archive/2007/07/16/130508.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>姝e垯琛ㄨ揪寮忕殑鎬葷粨http://www.tkk7.com/cherishchen/archive/2007/07/12/129757.html鍑爮瑙傛搗鍑爮瑙傛搗Thu, 12 Jul 2007 01:44:00 GMThttp://www.tkk7.com/cherishchen/archive/2007/07/12/129757.htmlhttp://www.tkk7.com/cherishchen/comments/129757.htmlhttp://www.tkk7.com/cherishchen/archive/2007/07/12/129757.html#Feedback2http://www.tkk7.com/cherishchen/comments/commentRss/129757.htmlhttp://www.tkk7.com/cherishchen/services/trackbacks/129757.html涓銆丣DK鎻愪緵鐨勬鍒欒〃杈懼紡

Java's java.util.regex 鍖呭寘鎷細(xì)Pattern綾匯丮atcher綾匯丮atchResult鎺ュ彛鍜孭atternSyntaxException寮傚父錛?/p>

  • Pattern 瀵硅薄浠h〃浜嗙紪璇戜簡鐨勬鍒欒〃杈懼紡錛圓 compiled representation of a regular expression.錛夈?
  • Matcher 錛孉n engine that performs match operations on a character sequence by interpreting a Pattern.
  • MatchResult鎺ュ彛錛歍he result of a match operation.
  • PatternSyntaxException瀵硅薄錛屾弿榪伴潪娉曠殑regex patterns錛孶nchecked exception thrown to indicate a syntax error in a regular-expression pattern.

 鍚屾椂榪橀渶瑕佷簡瑙f槸CharSequence錛孞DK 1.4瀹氫箟鐨勬柊鐨勬帴鍙o紝瀹冩彁渚涗簡String鍜孲tringBuffer榪欎袱涓被鐨勫瓧絎﹀簭鍒楃殑鎶借薄

interface CharSequence {

charAt(int i);

length();

subSequence(int start, int end);

toString();

}

涓轟簡瀹炵幇榪欎釜鏂扮殑CharSequence鎺ュ彛錛孲tring錛孲tringBuffer浠ュ強(qiáng)CharBuffer閮戒綔浜嗕慨鏀癸紝寰堝鐨勬鍒欒〃杈懼紡鐨勬搷浣滈兘瑕佹嬁CharSequence浣滃弬鏁般?

 

Matcher綾葷殑鍑犱釜閲嶈鐨勬柟娉曪細(xì)

  • boolean matches()錛歅attern鍖歸厤鏁翠釜瀛楃涓?
  • boolean lookingAt()錛歅attern鍖歸厤瀛楃涓茬殑寮澶?
  • boolean find()錛氬彂鐜癈harSequence閲岀殑錛屼笌pattern鐩稿尮閰嶇殑澶氫釜瀛楃搴忓垪
    boolean find(int start)錛氬憡璇夋柟娉曚粠鍙傛暟start浣嶇疆寮濮嬫煡鎵?/li>

group鐨勬蹇?/h2>

Group鏄寚閲岀敤鎷彿鎷搗鏉ョ殑錛岃兘琚悗闈㈢殑琛ㄨ揪寮忚皟鐢ㄧ殑姝e垯琛ㄨ揪寮忋?/p>

Group 0 琛ㄧず鏁翠釜琛ㄨ揪寮忥紝group 1琛ㄧず絎竴涓鎷搗鏉ョ殑group錛屼互姝ょ被鎺ㄣ傛墍浠ワ紱

A(B(C))D

閲岄潰鏈変笁涓猤roup錛歡roup 0鏄疉BCD錛?group 1鏄疊C錛実roup 2鏄疌銆?

浣犲彲浠ョ敤涓嬭堪Matcher鏂規(guī)硶鏉ヤ嬌鐢╣roup錛?

  • public int groupCount( )榪斿洖matcher瀵硅薄涓殑group鐨勬暟鐩備笉鍖呮嫭group0銆?
  • public String group( ) 榪斿洖涓婃鍖歸厤鎿嶄綔(姣旀柟璇磃ind( ))鐨刧roup 0(鏁翠釜鍖歸厤)
  • public String group(int i)榪斿洖涓婃鍖歸厤鎿嶄綔鐨勬煇涓猤roup銆傚鏋滃尮閰嶆垚鍔燂紝浣嗘槸娌¤兘鎵懼埌group錛屽垯榪斿洖null銆?
  • public int start(int group)榪斿洖涓婃鍖歸厤鎵鎵懼埌鐨刧roup鐨勫紑濮嬩綅緗?
  • public int end(int group)榪斿洖涓婃鍖歸厤鎵鎵懼埌鐨刧roup鐨勭粨鏉熶綅緗紝鏈鍚庝竴涓瓧絎︾殑涓嬫爣鍔犱竴銆?
  • split( ) 鏄寚灝嗕互姝e垯琛ㄨ揪寮忎負(fù)鐣岋紝灝嗗瓧絎︿覆鍒嗗壊鎴怱tring鏁扮粍,濡傛灉甯︽湁limit鍙傛暟錛宻plit( )浼?xì)闄愬畾鍒嗗壊鐨剫啤鏁般?
  • replaceFirst(String replacement)灝嗗瓧絎︿覆閲岋紝絎竴涓笌妯″紡鐩稿尮閰嶇殑瀛愪覆鏇挎崲鎴恟eplacement銆?
  • replaceAll(String replacement)錛屽皢杈撳叆瀛楃涓查噷鎵鏈変笌妯″紡鐩稿尮閰嶇殑瀛愪覆鍏ㄩ儴鏇挎崲鎴恟eplacement銆?
  • appendReplacement(StringBuffer sbuf, String replacement)瀵箂buf榪涜閫愭鏇挎崲錛岃屼笉鏄儚replaceFirst( )鎴杛eplaceAll( )閭f牱錛屽彧鏇挎崲絎竴涓垨鍏ㄩ儴瀛愪覆銆傝繖鏄釜闈炲父閲嶈鐨勬柟娉曪紝鍥犱負(fù)replacement(replaceFirst( )鍜宺eplaceAll( )鍙厑璁哥敤鍥哄畾鐨勫瓧絎︿覆鏉ュ厖褰搑eplacement)銆傛湁浜嗚繖涓柟娉曪紝浣犲氨鍙互緙栫▼鍖哄垎group錛屼粠鑰屽疄鐜版洿寮哄ぇ鐨勬浛鎹㈠姛鑳姐?
  • 璋冪敤瀹宎ppendReplacement( )涔嬪悗錛屼負(fù)浜嗘妸鍓╀綑鐨勫瓧絎︿覆鎷瘋礉鍥炲幓錛屽繀欏昏皟鐢╝ppendTail(StringBuffer sbuf, String replacement)銆?

 

浣跨敤group鍙互鍋氬埌閫愭緙╁皬鍖歸厤鐨勮寖鍥達(dá)紝鐩磋嚦綺劇‘鍖歸厤鐨勭洰鐨勩?

start( )鍜宔nd( )錛氬鏋滃尮閰嶆垚鍔燂紝start( )浼?xì)杩斿洖姝啤鍖归厤鐨勫紑濮嬩綅緗紝end( )浼?xì)杩斿洖姝啤鍖归厤鐨劸l撴潫浣嶇疆錛屽嵆鏈鍚庝竴涓瓧絎︾殑涓嬫爣鍔犱竴銆傚鏋滀箣鍓嶇殑鍖歸厤涓嶆垚鍔?鎴栬呮病鍖歸厤)錛岄偅涔堟棤璁烘槸璋冪敤start( )榪樻槸end( )錛岄兘浼?xì)寮曞彂涓涓狪llegalStateException銆?/p>

 

浜屻?澶т嬌鐢ㄦ柟娉曪細(xì)

鏌ヨ

String str="abc efg ABC";

 

String regEx="a|f"; //琛ㄧずa鎴杅

 

Pattern p=Pattern.compile(regEx);

 

Matcher m=p.matcher(str);

 

boolean rs=m.find();

 

濡傛灉str涓湁regEx錛岄偅涔坮s涓簍rue錛屽惁鍒欎負(fù)flase銆傚鏋滄兂鍦ㄦ煡鎵炬椂蹇界暐澶у皬鍐欙紝鍒欏彲浠ュ啓鎴怭attern p=Pattern.compile(regEx,Pattern.CASE_INSENSITIVE);

 

 

鎻愬彇

String regEx=".+\\\\(.+)$";

 

String str="c:\\dir1\\dir2\\name.txt";

 

Pattern p=Pattern.compile(regEx);

 

Matcher m=p.matcher(str);

 

boolean rs=m.find();

 

for(int i=1;i<=m.groupCount();i++){

 

System.out.println(m.group(i));

 

}

 

浠ヤ笂鐨勬墽琛岀粨鏋滀負(fù)name.txt錛屾彁鍙栫殑瀛楃涓插偍瀛樺湪m.group(i)涓紝鍏朵腑i鏈澶у間負(fù)m.groupCount();

 

 

鍒嗗壊

 

String regEx="::";

 

Pattern p=Pattern.compile(regEx);

 

String[] r=p.split("xd::abc::cde");

 

鎵ц鍚庯紝r灝辨槸{"xd","abc","cde"}錛屽叾瀹炲垎鍓叉椂榪樻湁璺熺畝鍗曠殑鏂規(guī)硶錛?

 

String str="xd::abc::cde";

 

String[] r=str.split("::");

 

 

鏇挎崲鎴栬呭垹闄?/strong>

String regEx="a+"; //琛ㄧず涓涓垨澶氫釜a

 

Pattern p=Pattern.compile(regEx);

 

Matcher m=p.matcher("aaabbced a ccdeaa");

 

String s=m.replaceAll("A");

 

緇撴灉涓?Abbced A ccdeA"

 

濡傛灉鍐欐垚絀轟覆錛屾棦鍙揪鍒板垹闄ょ殑鍔熻兘錛屾瘮濡傦細(xì)

 

String s=m.replaceAll("");

 

緇撴灉涓?bbced ccde"

 

 

涓夈佷竴涓疄闄呯殑渚嬪瓙

涓嬮潰鐨勫嚱鏁版槸涓涓疄闄呭簲鐢ㄧ殑渚嬪瓙錛岄渶姹傛槸闇瑕佸皢鎶撳彇鐨勭綉欏典腑鐨?lt;img src=''http://aa.bb.cc.com/images/**.jpg"> 涓殑鍦板潃錛屼繚瀛樺埌涓涓湴鍧鍒楄〃涓紙浠ヤ緵鎶撳彇鍥劇墖浣跨敤錛夛紝騫跺皢緇濆鍦板潃鏇挎崲鎴愭湰鍦扮殑鐩稿鍦板潃錛屽嵆<img src="images/**.jpg">銆?/p>

public static Map<String, String> getImagesURL(String description) {

      Map<String, String> map = new HashMap<String, String>();
        // img 鐨勬鍒欒〃杈懼紡:鍖歸厤<img>鏍囩       
        String imgPattern = "<\\s*img\\s+([^>]+)\\s*>";
        Pattern pattern1 = Pattern.compile(imgPattern, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern1.matcher(description);

        // img src鍏冪礌鐨勬鍒欒〃杈懼紡錛氬尮閰峣mg鏍囩鍐呯殑src灞炴?br />         String srcPattern = "\\s*src\\s*=\\s*\"([^\"]+)\\s*\"";
        Pattern pattern2 = Pattern.compile(srcPattern, Pattern.CASE_INSENSITIVE);

        while (matcher.find()) {

           //group()榪斿洖絎﹀悎琛ㄨ揪寮忕殑鍐呭
            Matcher matcher2 = pattern2 .matcher(matcher.group());
            // 涓瀹氳find(),榪欐槸瀹為檯鐨勫尮閰嶅姩浣?br />             if (matcher2.find()) {
                String src = matcher2.group();
                log.info(src);
                int i2 = src.lastIndexOf('/');
                int i1 = src.indexOf("http");
                if (i1 != -1) {
                    map.put(src.substring(i2 + 1, src.length() - 1), src
                            .substring(i1, src.length() - 1));
                }
            }
        }
        log.debug("鍥劇墖錛? + map);
        return map;
    }

 

鏁翠綋鎬濊礬鏄厛鍖歸厤鍒癷mg鏍囩錛岀劧鍚庡尮閰峴rc灞炴э紝騫朵慨鏀箂rc鐨勫睘鎬?/p>

"<\\s*img\\s+([^>]+)\\s*>" 鐨勮В閲婏細(xì)

\\s* :0 鎴栧涓┖鏍?nbsp;  \\s+: 鑷沖皯涓涓┖鏍?/p>

([^>]+)錛氭寚鐨勬槸闈?gt;鐨勬墍鏈夌殑瀛楃錛岃嚦灝戜竴涓?/p>

 

甯哥敤鐨勬鍒欒〃杈懼紡錛堝弬鑰僯dk鐨剅egex鏂囨。錛?/h1>

瀛楃闆嗙被

.                            琛ㄧず浠繪剰涓涓瓧絎?

[abc]                     琛ㄧず瀛楃a錛宐錛宑涓殑浠繪剰涓涓?涓巃|b|c鐩稿悓)

[^abc]                   闄錛宐錛宑涔嬪鐨勪換鎰忎竴涓瓧絎?鍚﹀畾)

[a-zA-Z]                浠巃鍒皕鎴朅鍒癦褰撲腑鐨勪換鎰忎竴涓瓧絎?鑼冨洿)

[abc[hij]]              a,b,c,h,i,j涓殑浠繪剰涓涓瓧絎?涓巃|b|c|h|i|j鐩稿悓)(騫墮泦)

[a-z&&[hij]]          h,i,j涓殑涓涓?浜ら泦)

\s                          絀烘牸瀛楃(絀烘牸閿? tab, 鎹㈣, 鎹㈤〉, 鍥炶濺)

\S                         闈炵┖鏍煎瓧絎?[^\s])

\d                         涓涓暟瀛楋紝涔熷氨鏄痆0-9]

\D                         涓涓潪鏁板瓧鐨勫瓧絎︼紝涔熷氨鏄痆^0-9]

\w                        涓涓崟璇嶅瓧絎?word character)錛屽嵆[a-zA-Z_0-9]

\W                       涓涓潪鍗曡瘝鐨勫瓧絎︼紝[^\w]

瀛楃綾伙細(xì)

B                         瀛楃B

\xhh                    16榪涘埗鍊?xhh鎵琛ㄧず鐨勫瓧絎?

\uhhhh                16榪涘埗鍊?xhhhh鎵琛ㄧず鐨刄nicode瀛楃

\t                         Tab

\n                        鎹㈣絎?

\r                         鍥炶濺絎?

\f                        鎹㈤〉絎?

\e                       Escape

閫昏緫榪愮畻絎?/strong>

XY                      X 鍚庨潰璺熺潃 Y

X|Y                    X鎴朰

(X)                     涓涓?瑕佸尮閰嶇殑緇?capturing group)". 浠ュ悗鍙互鐢╘i鏉ヨ〃紺虹i涓鍖歸厤鐨勭粍銆?

杈圭晫鍖歸厤絎?/strong>

^                      涓琛岀殑寮濮?

$                      涓琛岀殑緇撳熬

\b                    涓涓崟璇嶇殑杈圭晫

\B                    涓涓潪鍗曡瘝鐨勮竟鐣?

\G                   鍓嶄竴涓尮閰嶇殑緇撴潫

 

鏁伴噺琛ㄧず絎?/strong>

"鏁伴噺琛ㄧず絎?quantifier)"鐨勪綔鐢ㄦ槸瀹氫箟妯″紡搴旇鍖歸厤澶氬皯涓瓧絎︺?

  • Greedy(璐┆鐨?錛?闄ら潪鍙︽湁琛ㄧず錛屽惁鍒欐暟閲忚〃紺虹閮芥槸greedy鐨勩侴reedy鐨勮〃杈懼紡浼?xì)涓鐩村尮閰嶄笅鍘伙紝鐩村埌鍖歸厤涓嶄笅鍘諱負(fù)姝€?u>(濡傛灉浣犲彂鐜拌〃杈懼紡鍖歸厤鐨勭粨鏋滀笌棰勬湡鐨勪笉絎?錛屽緢鏈夊彲鑳芥槸鍥犱負(fù)錛屼綘浠ヤ負(fù)琛ㄨ揪寮忎細(xì)鍙尮閰嶅墠闈㈠嚑涓瓧絎︼紝鑰屽疄闄呬笂瀹冩槸greedy鐨勶紝鍥犳浼?xì)涓鐩村尮閰嶄笅鍘匯?
  • Reluctant(鍕夊己鐨?錛?鐢ㄩ棶鍙瘋〃紺猴紝瀹冧細(xì)鍖歸厤鏈灝戠殑瀛楃銆備篃縐頒負(fù)lazy, minimal matching, non-greedy, 鎴杣ngreedy銆?
  • Possessive(鍗犳湁鐨?錛?鐩墠鍙湁Java鏀寔(鍏跺畠璇█閮戒笉鏀寔)銆傚畠鏇村姞鍏堣繘錛屾墍浠ヤ綘鍙兘榪樹笉澶細(xì)鐢ㄣ傜敤姝e垯琛ㄨ揪寮忓尮閰嶅瓧絎︿覆鐨勬椂鍊欎細(xì)浜х敓寰堝涓棿鐘舵侊紝(涓鑸殑鍖歸厤寮曟搸浼?xì)淇濆瓨杩櫩U嶄腑闂寸姸鎬侊紝)榪欐牱鍖歸厤澶辮觸鐨勬椂鍊欏氨鑳藉師璺繑鍥炰簡銆傚崰鏈夊瀷鐨勮〃杈懼紡涓嶄繚瀛樿繖縐嶄腑闂寸姸鎬侊紝鍥犳涔熷氨涓嶄細(xì)鍥炲ご閲嶆潵浜嗐傚畠鑳介槻姝㈡鍒欒〃杈懼紡鐨勫け鎺э紝鍚屾椂涔熻兘鎻愰珮榪愯鐨勬晥鐜囥?

 

Greedy                    Reluctant                           Possessive                      鍖歸厤

 

X?                            X??                                      X?+                                  鍖歸厤涓涓垨闆朵釜X

X*                            X*?                                      X*+                                  鍖歸厤闆舵垨澶氫釜X

X+                           X+?                                      X++                                 鍖歸厤涓涓垨澶氫釜X

X{n}                        X{n}?                                   X{n}+                               鍖歸厤姝eソn涓猉

X{n,}                       X{n,}?                                 X{n,}+                              鍖歸厤鑷沖皯n涓猉

X{n,m}                   X{n,m}?                                X{n,m}+                           鍖歸厤鑷沖皯n涓紝鑷沖m涓猉

 

 

鍙傝冭祫鏂?/h2>

瑕佹兂榪涗竴姝ュ涔?fàn)姝e垯琛ㄨ緫旨忓Q屽緩璁湅Mastering Regular Expression, 2nd Edition錛屼綔鑰匤effrey E. F. Friedl (O’Reilly, 2002)銆?

"Regular Expressions and the Java Programming Language," Dana Nourie and Mike McCloskey (Sun Microsystems, August 2002) presents a brief overview of java.util.regex, including five illustrative regex-based applications:
http://developer.java.sun.com/developer/technicalArticles/releases/1.4regex/

http://www.tkk7.com/beike/archive/2006/04/28/43832.html 

http://wcjok.bokee.com/4293762.html



]]>鐢℉ttpClient鏉ユā鎷熸祻瑙堝櫒GET POST(鏀惰棌)http://www.tkk7.com/cherishchen/archive/2007/07/10/129369.html鍑爮瑙傛搗鍑爮瑙傛搗Tue, 10 Jul 2007 08:05:00 GMThttp://www.tkk7.com/cherishchen/archive/2007/07/10/129369.htmlhttp://www.tkk7.com/cherishchen/comments/129369.htmlhttp://www.tkk7.com/cherishchen/archive/2007/07/10/129369.html#Feedback1http://www.tkk7.com/cherishchen/comments/commentRss/129369.htmlhttp://www.tkk7.com/cherishchen/services/trackbacks/129369.html鐢℉ttpClient鏉ユā鎷熸祻瑙堝櫒GET POST

http://www.xd-tech.com.cn/blog/article.asp?id=34

浣滆?jaddy0302 鏃ユ湡:2006-12-21

      涓鑸殑鎯呭喌涓嬫垜浠兘鏄嬌鐢↖E鎴栬匩avigator嫻忚鍣ㄦ潵璁塊棶涓涓猈EB鏈嶅姟鍣紝鐢ㄦ潵嫻忚欏甸潰鏌ョ湅淇℃伅鎴栬呮彁浜や竴浜涙暟鎹瓑絳夈傛墍璁塊棶鐨勮繖浜涢〉闈㈡湁鐨勪粎浠呮槸涓浜涙櫘閫氱殑欏甸潰錛屾湁鐨勯渶瑕佺敤鎴風(fēng)櫥褰曞悗鏂瑰彲浣跨敤錛屾垨鑰呴渶瑕佽璇佷互鍙?qiáng)鏄竴浜涢氳繃鍔犲瘑鏂瑰紡浼犺緭錛屼緥濡侶TTPS銆傜洰鍓嶆垜浠嬌鐢ㄧ殑嫻忚鍣ㄥ鐞嗚繖浜涙儏鍐甸兘涓嶄細(xì)鏋勬垚闂銆備笉榪囦綘鍙兘鍦ㄦ煇浜涙椂鍊欓渶瑕侀氳繃紼嬪簭鏉ヨ闂繖鏍風(fēng)殑涓浜涢〉闈紝姣斿浠庡埆浜虹殑緗戦〉涓滃伔鈥濅竴浜涙暟鎹紱鍒╃敤鏌愪簺绔欑偣鎻愪緵鐨勯〉闈㈡潵瀹屾垚鏌愮鍔熻兘錛屼緥濡傝鎴戜滑鎯崇煡閬撴煇涓墜鏈哄彿鐮佺殑褰掑睘鍦拌屾垜浠嚜宸卞張娌℃湁榪欐牱鐨勬暟鎹紝鍥犳鍙ソ鍊熷姪鍏朵粬鍏徃宸叉湁鐨勭綉绔欐潵瀹屾垚榪欎釜鍔熻兘錛岃繖涓椂鍊欐垜浠渶瑕佸悜緗戦〉鎻愪氦鎵嬫満鍙風(fēng)爜騫朵粠榪斿洖鐨勯〉闈腑瑙f瀽鍑烘垜浠兂瑕佺殑鏁版嵁鏉ャ傚鏋滃鏂逛粎浠呮槸涓涓緢綆鍗曠殑欏甸潰錛岄偅鎴戜滑鐨勭▼搴忎細(xì)寰堢畝鍗曪紝鏈枃涔熷氨娌℃湁蹇呰澶у紶鏃楅紦鐨勫湪榪欓噷嫻垂鍙h垖銆備絾鏄冭檻鍒頒竴浜涙湇鍔℃巿鏉冪殑闂錛屽緢澶氬叕鍙告彁渚涚殑欏甸潰寰寰騫朵笉鏄彲浠ラ氳繃涓涓畝鍗曠殑URL灝卞彲浠ヨ闂殑錛岃屽繀欏葷粡榪囨敞鍐岀劧鍚庣櫥褰曞悗鏂瑰彲浣跨敤鎻愪緵鏈嶅姟鐨勯〉闈紝榪欎釜鏃跺欏氨娑夊強(qiáng)鍒?COOKIE闂鐨勫鐞嗐傛垜浠煡閬撶洰鍓嶆祦琛岀殑***欏墊妧鏈緥濡侫SP銆丣SP鏃犱笉鏄氳繃COOKIE鏉ュ鐞嗕細(xì)璇濅俊鎭殑銆備負(fù)浜嗕嬌鎴戜滑鐨勭▼搴忚兘浣跨敤鍒漢鎵鎻愪緵鐨勬湇鍔¢〉闈紝灝辮姹傜▼搴忛鍏堢櫥褰曞悗鍐嶈闂湇鍔¢〉闈紝榪欒繃紼嬪氨闇瑕佽嚜琛屽鐞哻ookie錛屾兂鎯沖綋浣犵敤java.net.HttpURLConnection 鏉ュ畬鎴愯繖浜涘姛鑳芥椂鏄涔堟亹鎬栫殑浜嬫儏鍟婏紒鍐典笖榪欎粎浠呮槸鎴戜滑鎵璇寸殑欏藉浐鐨刉EB鏈嶅姟鍣ㄤ腑鐨勪竴涓緢甯歌鐨勨滈〗鍥衡濓紒鍐嶆湁濡傞氳繃HTTP鏉ヤ笂浼犳枃浠跺憿錛熶笉闇瑕佸ご鐤鹼紝榪欎簺闂鏈変簡鈥滃畠鈥濆氨寰堝鏄撹В鍐充簡錛?

鎴戜滑涓嶅彲鑳藉垪涓炬墍鏈夊彲鑳界殑欏藉浐錛屾垜浠細(xì)閽堝鍑犵鏈甯歌鐨勯棶棰樿繘琛屽鐞嗐傚綋鐒朵簡錛屾濡傚墠闈㈣鍒扮殑錛屽鏋滄垜浠嚜宸變嬌鐢?java.net.HttpURLConnection鏉ユ悶瀹氳繖浜涢棶棰樻槸寰堟亹鎬栫殑浜嬫儏錛屽洜姝ゅ湪寮濮嬩箣鍓嶆垜浠厛瑕佷粙緇嶄竴涓嬩竴涓紑鏀炬簮鐮佺殑欏圭洰錛岃繖涓」鐩氨鏄?Apache寮婧愮粍緇囦腑鐨刪ttpclient錛屽畠闅跺睘浜嶫akarta鐨刢ommons欏圭洰錛岀洰鍓嶇殑鐗堟湰鏄?.0RC2銆俢ommons涓嬫湰鏉ュ凡緇忔湁涓涓猲et鐨勫瓙欏圭洰錛屼絾鏄張鎶奾ttpclient鍗曠嫭鎻愬嚭鏉ワ紝鍙http鏈嶅姟鍣ㄧ殑璁塊棶緇濋潪鏄撲簨銆?

Commons-httpclient欏圭洰灝辨槸涓撻棬璁捐鏉ョ畝鍖朒TTP瀹㈡埛绔笌鏈嶅姟鍣ㄨ繘琛屽悇縐嶉氳緙栫▼銆傞氳繃瀹冨彲浠ヨ鍘熸潵寰堝ご鐤肩殑浜嬫儏鐜板湪杞繪澗鐨勮В鍐籌紝渚嬪浣犱笉鍐嶇鏄疕TTP鎴栬匟TTPS鐨勯氳鏂瑰紡錛屽憡璇夊畠浣犳兂浣跨敤HTTPS鏂瑰紡錛屽墿涓嬬殑浜嬫儏浜ょ粰 httpclient鏇夸綘瀹屾垚銆傛湰鏂囦細(xì)閽堝鎴戜滑鍦ㄧ紪鍐橦TTP瀹㈡埛绔▼搴忔椂緇忓父紕板埌鐨勫嚑涓棶棰樿繘琛屽垎鍒粙緇嶅浣曚嬌鐢╤ttpclient鏉ヨВ鍐沖畠浠紝涓轟簡璁╄鑰呮洿蹇殑鐔熸?zhèn)墭q欎釜欏圭洰鎴戜滑鏈寮濮嬪厛緇欏嚭涓涓畝鍗曠殑渚嬪瓙鏉ヨ鍙栦竴涓綉欏電殑鍐呭錛岀劧鍚庡驚搴忔笎榪涜В鍐蟲帀鍓嶈繘涓殑鎵褰緧鐙?/font>

1錛?璇誨彇緗戦〉(HTTP/HTTPS)鍐呭

涓嬮潰鏄垜浠粰鍑虹殑涓涓畝鍗曠殑渚嬪瓙鐢ㄦ潵璁塊棶鏌愪釜欏甸潰

/*

 * Created on 2003-12-14 by Liudong

 */

package http.demo;

import java.io.IOException;

import org.apache.commons.httpclient.*;

import org.apache.commons.httpclient.methods.*;

/**

 * 鏈綆鍗曠殑HTTP瀹㈡埛绔?鐢ㄦ潵婕旂ず閫氳繃GET鎴栬匬OST鏂瑰紡璁塊棶鏌愪釜欏甸潰

 * @author Liudong

 */

public class SimpleClient {

    public static void main(String[] args) throws IOException

    {

        HttpClient client = new HttpClient();   

        //璁劇疆浠g悊鏈嶅姟鍣ㄥ湴鍧鍜岀鍙?nbsp;   

        //client.getHostConfiguration().setProxy("proxy_host_addr",proxy_port);

        //浣跨敤GET鏂規(guī)硶錛屽鏋滄湇鍔″櫒闇瑕侀氳繃HTTPS榪炴帴錛岄偅鍙渶瑕佸皢涓嬮潰URL涓殑http鎹㈡垚https

        HttpMethod method = new GetMethod("        //浣跨敤POST鏂規(guī)硶

        //HttpMethod method = new PostMethod("        client.executeMethod(method);

        //鎵撳嵃鏈嶅姟鍣ㄨ繑鍥炵殑鐘舵?

        System.out.println(method.getStatusLine());

        //鎵撳嵃榪斿洖鐨勪俊鎭?

        System.out.println(method.getResponseBodyAsString());

        //閲婃斁榪炴帴

        method.releaseConnection();

    }
}

鍦ㄨ繖涓緥瀛愪腑棣栧厛鍒涘緩涓涓狧TTP瀹㈡埛绔?HttpClient)鐨勫疄渚嬶紝鐒跺悗閫夋嫨鎻愪氦鐨勬柟娉曟槸GET鎴栬?POST錛屾渶鍚庡湪HttpClient瀹炰緥涓婃墽琛屾彁浜ょ殑鏂規(guī)硶錛屾渶鍚庝粠鎵閫夋嫨鐨勬彁浜ゆ柟娉曚腑璇誨彇鏈嶅姟鍣ㄥ弽棣堝洖鏉ョ殑緇撴灉銆傝繖灝辨槸浣跨敤HttpClient鐨勫熀鏈祦紼嬨傚叾瀹炵敤涓琛屼唬鐮佷篃灝卞彲浠ユ悶瀹氭暣涓姹傜殑榪囩▼錛岄潪甯哥殑綆鍗曪紒

2錛?浠ET鎴栬匬OST鏂瑰紡鍚戠綉欏墊彁浜ゅ弬鏁?

鍏跺疄鍓嶉潰涓涓渶綆鍗曠殑紺轟緥涓垜浠凡緇忎粙緇嶄簡濡備綍浣跨敤GET鎴栬匬OST鏂瑰紡鏉ヨ姹備竴涓〉闈紝鏈皬鑺備笌涔嬩笉鍚岀殑鏄浜嗘彁浜ゆ椂璁懼畾欏甸潰鎵闇鐨勫弬鏁幫紝鎴戜滑鐭ラ亾濡傛灉鏄疓ET鐨勮姹傛柟寮忥紝閭d箞鎵鏈夊弬鏁伴兘鐩存帴鏀懼埌欏甸潰鐨刄RL鍚庨潰鐢ㄩ棶鍙蜂笌欏甸潰鍦板潃闅斿紑錛屾瘡涓弬鏁扮敤&闅斿紑錛屼緥濡傦細(xì)http://java.sun.com?name=liudong&mobile=123456錛屼絾鏄綋浣跨敤POST鏂規(guī)硶鏃跺氨浼?xì)绋嶅井鏈変竴鐐圭偣楹葷儲銆傛湰灝忚妭鐨勪緥瀛愭紨紺哄悜濡備綍鏌ヨ鎵嬫満鍙風(fēng)爜鎵鍦ㄧ殑鍩庡競錛屼唬鐮佸涓嬶細(xì)

/*

 * Created on 2003-12-7 by Liudong

 */

package http.demo;

import java.io.IOException;

import org.apache.commons.httpclient.*;

import org.apache.commons.httpclient.methods.*;

/**

 * 鎻愪氦鍙傛暟婕旂ず

 * 璇ョ▼搴忚繛鎺ュ埌涓涓敤浜庢煡璇㈡墜鏈哄彿鐮佹墍灞炲湴鐨勯〉闈?

 * 浠ヤ究鏌ヨ鍙風(fēng)爜孌?330227鎵鍦ㄧ殑鐪佷喚浠ュ強(qiáng)鍩庡競

 * @author Liudong

 */

public class SimpleHttpClient {

    public static void main(String[] args) throws IOException

    {

        HttpClient client = new HttpClient();

        client.getHostConfiguration().setHost("        HttpMethod method = getPostMethod();//浣跨敤POST鏂瑰紡鎻愪氦鏁版嵁

        client.executeMethod(method);

       //鎵撳嵃鏈嶅姟鍣ㄨ繑鍥炵殑鐘舵?

        System.out.println(method.getStatusLine());

        //鎵撳嵃緇撴灉欏甸潰

        String response =  new String(method.getResponseBodyAsString().getBytes("8859_1"));

       //鎵撳嵃榪斿洖鐨勪俊鎭?

        System.out.println(response);

        method.releaseConnection();

    }

    /**

     * 浣跨敤GET鏂瑰紡鎻愪氦鏁版嵁

     * @return

     */

    private static HttpMethod getGetMethod(){

        return new GetMethod("/simcard.php?simcard=1330227");

    }

    /**

     * 浣跨敤POST鏂瑰紡鎻愪氦鏁版嵁

     * @return

     */

    private static HttpMethod getPostMethod(){

        PostMethod post = new PostMethod("/simcard.php");

        NameValuePair simcard = new NameValuePair("simcard","1330227");

        post.setRequestBody(new NameValuePair[] { simcard});

        return post;

    }

}

鍦ㄤ笂闈㈢殑渚嬪瓙涓〉闈?a >http://www.imobile.com.cn/simcard.php闇瑕佷竴涓弬鏁版槸simcard錛岃繖涓弬鏁板間負(fù)鎵嬫満鍙風(fēng)爜孌碉紝鍗蟲墜鏈哄彿鐮佺殑鍓嶄竷浣嶏紝鏈嶅姟鍣ㄤ細(xì)榪斿洖鎻愪氦鐨勬墜鏈哄彿鐮佸搴旂殑鐪佷喚銆佸煄甯備互鍙?qiáng)鍏朵粬璇l嗕俊鎭侴ET鐨勬彁浜ゆ柟娉曞彧闇瑕佸湪URL鍚庡姞鍏ュ弬鏁頒俊鎭紝鑰孭OST鍒欓渶瑕侀氳繃NameValuePair綾繪潵璁劇疆鍙傛暟鍚嶇О鍜屽畠鎵瀵瑰簲鐨勫?

3錛?澶勭悊欏甸潰閲嶅畾鍚?

鍦↗SP/Servlet緙栫▼涓璻esponse.sendRedirect鏂規(guī)硶灝辨槸浣跨敤HTTP鍗忚涓殑閲嶅畾鍚戞満鍒躲傚畠涓嶫SP涓殑<jsp:forward 鈥?gt;鐨勫尯鍒湪浜庡悗鑰呮槸鍦ㄦ湇鍔″櫒涓疄鐜伴〉闈㈢殑璺寵漿錛屼篃灝辨槸璇村簲鐢ㄥ鍣ㄥ姞杞戒簡鎵瑕佽煩杞殑欏甸潰鐨勫唴瀹瑰茍榪斿洖緇欏鎴風(fēng)錛涜屽墠鑰呮槸榪斿洖涓涓姸鎬佺爜錛岃繖浜涚姸鎬佺爜鐨勫彲鑳藉艱涓嬭〃錛岀劧鍚庡鎴風(fēng)璇誨彇闇瑕佽煩杞埌鐨勯〉闈㈢殑URL騫墮噸鏂板姞杞芥柊鐨勯〉闈€傚氨鏄繖鏍蜂竴涓繃紼嬶紝鎵浠ユ垜浠紪紼嬬殑鏃跺欏氨瑕侀氳繃 HttpMethod.getStatusCode()鏂規(guī)硶鍒ゆ柇榪斿洖鍊兼槸鍚︿負(fù)涓嬭〃涓殑鏌愪釜鍊兼潵鍒ゆ柇鏄惁闇瑕佽煩杞傚鏋滃凡緇忕‘璁ら渶瑕佽繘琛岄〉闈㈣煩杞簡錛岄偅涔堝彲浠ラ氳繃璇誨彇HTTP澶翠腑鐨刲ocation灞炴ф潵鑾峰彇鏂扮殑鍦板潃銆?

鐘舵佺爜
 瀵瑰簲HttpServletResponse鐨勫父閲?br> 璇︾粏鎻忚堪
301銆 SC_MOVED_PERMANENTLY
 欏甸潰宸茬粡姘鎬箙縐誨埌鍙﹀涓涓柊鍦板潃
302銆 SC_MOVED_TEMPORARILY
 欏甸潰鏆傛椂縐誨姩鍒板彟澶栦竴涓柊鐨勫湴鍧
303銆 SC_SEE_OTHER
 瀹㈡埛绔姹傜殑鍦板潃蹇呴』閫氳繃鍙﹀鐨刄RL鏉ヨ闂?br>307銆 SC_TEMPORARY_REDIRECT銆 鍚孲C_MOVED_TEMPORARILY

涓嬮潰鐨勪唬鐮佺墖孌墊紨紺哄浣曞鐞嗛〉闈㈢殑閲嶅畾鍚?

client.executeMethod(post);

        System.out.println(post.getStatusLine().toString());

        post.releaseConnection();

        //媯鏌ユ槸鍚﹂噸瀹氬悜

        int statuscode = post.getStatusCode();

        if ((statuscode == HttpStatus.SC_MOVED_TEMPORARILY) ||

            (statuscode == HttpStatus.SC_MOVED_PERMANENTLY) ||

            (statuscode == HttpStatus.SC_SEE_OTHER) ||

(statuscode == HttpStatus.SC_TEMPORARY_REDIRECT)) {

//璇誨彇鏂扮殑URL鍦板潃

            Header header = post.getResponseHeader("location");

            if (header != null) {

                String newuri = header.getValue();

                if ((newuri == null) || (newuri.equals("")))

                    newuri = "/";

                GetMethod redirect = new GetMethod(newuri);

                client.executeMethod(redirect);

                System.out.println("Redirect:"+ redirect.getStatusLine().toString());

                redirect.releaseConnection();

            } else

                System.out.println("Invalid redirect");

        }

鎴戜滑鍙互鑷緙栧啓涓や釜JSP欏甸潰錛屽叾涓竴涓〉闈㈢敤response.sendRedirect鏂規(guī)硶閲嶅畾鍚戝埌鍙﹀涓涓〉闈㈢敤鏉ユ祴璇曚笂闈㈢殑渚嬪瓙銆?

4錛?妯℃嫙杈撳叆鐢ㄦ埛鍚嶅拰鍙d護(hù)榪涜鐧誨綍

鏈皬鑺傚簲璇ヨ鏄疕TTP瀹㈡埛绔紪紼嬩腑鏈甯哥瑙佺殑闂錛屽緢澶氱綉绔欑殑鍐呭閮藉彧鏄娉ㄥ唽鐢ㄦ埛鍙鐨勶紝榪欑鎯呭喌涓嬪氨蹇呴』瑕佹眰浣跨敤姝g‘鐨勭敤鎴峰悕鍜屽彛浠ょ櫥褰曟垚鍔熷悗錛屾柟鍙祻瑙堝埌鎯寵鐨勯〉闈€傚洜涓篐TTP鍗忚鏄棤鐘舵佺殑錛屼篃灝辨槸榪炴帴鐨勬湁鏁堟湡鍙檺浜庡綋鍓嶈姹傦紝璇鋒眰鍐呭緇撴潫鍚庤繛鎺ュ氨鍏抽棴浜嗐傚湪榪欑鎯呭喌涓嬩負(fù)浜嗕繚瀛樼敤鎴風(fēng)殑鐧誨綍淇℃伅蹇呴』浣跨敤鍒癈ookie鏈哄埗銆備互JSP/Servlet涓轟緥錛屽綋嫻忚鍣ㄨ姹備竴涓狫SP鎴栬呮槸Servlet鐨勯〉闈㈡椂錛屽簲鐢ㄦ湇鍔″櫒浼?xì)杩斿洖涓涓弬鏁幫紝鍚嶄負(fù)jsessionid錛堝洜涓嶅悓搴旂敤鏈嶅姟鍣ㄨ屽紓錛夛紝鍊兼槸涓涓緝闀跨殑鍞竴瀛楃涓茬殑Cookie錛岃繖涓瓧絎︿覆鍊間篃灝辨槸褰撳墠璁塊棶璇ョ珯鐐圭殑浼?xì)璇濇爣璇嗐傛祻瑙堝櫒鍦ㄦ瘡璁塊棶璇ョ珯鐐圭殑鍏朵粬欏甸潰鏃跺欓兘瑕佸甫涓妀sessionid榪欐牱鐨凜ookie淇℃伅錛屽簲鐢ㄦ湇鍔″櫒鏍規(guī)嵁璇誨彇榪欎釜浼?xì)璇濇爣璇嗘潵鑾峰彇瀵瑰簲鐨勪細(xì)璇濅俊鎭?

瀵逛簬闇瑕佺敤鎴風(fēng)櫥褰曠殑緗戠珯錛屼竴鑸湪鐢ㄦ埛鐧誨綍鎴愬姛鍚庝細(xì)灝嗙敤鎴瘋祫鏂欎繚瀛樺湪鏈嶅姟鍣ㄧ殑浼?xì)璇濅腑锛寴q欐牱褰撹闂埌鍏朵粬鐨勯〉闈㈡椂鍊欙紝搴旂敤鏈嶅姟鍣ㄦ牴鎹祻瑙堝櫒閫佷笂鐨凜ookie涓鍙栧綋鍓嶈姹傚搴旂殑浼?xì)璇濇爣璇嗕互鑾峰緱瀵瑰簲鐨勪細(xì)璇濅俊鎭Q岀劧鍚庡氨鍙互鍒ゆ柇鐢ㄦ埛璧勬枡鏄惁瀛樺湪浜庝細(xì)璇濅俊鎭腑錛屽鏋滃瓨鍦ㄥ垯鍏佽璁塊棶欏甸潰錛屽惁鍒欒煩杞埌鐧誨綍欏甸潰涓姹傜敤鎴瘋緭鍏ュ笎鍙峰拰鍙d護(hù)榪涜鐧誨綍銆傝繖灝辨槸涓鑸嬌鐢↗SP寮鍙戠綉绔欏湪澶勭悊鐢ㄦ埛鐧誨綍鐨勬瘮杈冮氱敤鐨勬柟娉曘?

榪欐牱涓鏉ワ紝瀵逛簬HTTP鐨勫鎴風(fēng)鏉ヨ錛屽鏋滆璁塊棶涓涓彈淇濇姢鐨勯〉闈㈡椂灝卞繀欏繪ā鎷熸祻瑙堝櫒鎵鍋氱殑宸ヤ綔錛岄鍏堝氨鏄姹傜櫥褰曢〉闈紝鐒跺悗璇誨彇Cookie鍊鹼紱鍐嶆璇鋒眰鐧誨綍欏甸潰騫跺姞鍏ョ櫥褰曢〉鎵闇鐨勬瘡涓弬鏁幫紱鏈鍚庡氨鏄姹傛渶緇堟墍闇鐨勯〉闈€傚綋鐒跺湪闄ょ涓嬈¤姹傚鍏朵粬鐨勮姹傞兘闇瑕侀檮甯︿笂 Cookie淇℃伅浠ヤ究鏈嶅姟鍣ㄨ兘鍒ゆ柇褰撳墠璇鋒眰鏄惁宸茬粡閫氳繃楠岃瘉銆傝浜嗚繖涔堝錛屽彲鏄鏋滀綘浣跨敤httpclient鐨勮瘽錛屼綘鐢氳嚦榪炰竴琛屼唬鐮侀兘鏃犻渶澧炲姞錛屼綘鍙渶瑕佸厛浼犻掔櫥褰曚俊鎭墽琛岀櫥褰曡繃紼嬶紝鐒跺悗鐩存帴璁塊棶鎯寵鐨勯〉闈紝璺熻闂竴涓櫘閫氱殑欏甸潰娌℃湁浠諱綍鍖哄埆錛屽洜涓虹被HttpClient宸茬粡甯綘鍋氫簡鎵鏈夎鍋氱殑浜嬫儏浜嗭紝澶浜嗭紒涓嬮潰鐨勪緥瀛愬疄鐜頒簡榪欐牱涓涓闂殑榪囩▼銆?

/*

 * Created on 2003-12-7 by Liudong

 */

package http.demo;

import org.apache.commons.httpclient.*;

import org.apache.commons.httpclient.cookie.*;

import org.apache.commons.httpclient.methods.*;

/**

 * 鐢ㄦ潵婕旂ず鐧誨綍琛ㄥ崟鐨勭ず渚?

 * @author Liudong

 */

public class FormLoginDemo {

    static final String LOGON_SITE = "localhost";

    static final int    LOGON_PORT = 8080;

    public static void main(String[] args) throws Exception{

        HttpClient client = new HttpClient();

        client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT);

       //妯℃嫙鐧誨綍欏甸潰login.jsp->main.jsp

        PostMethod post = new PostMethod("/main.jsp");

        NameValuePair name = new NameValuePair("name", "ld");    

        NameValuePair pass = new NameValuePair("password", "ld");    

        post.setRequestBody(new NameValuePair[]{name,pass});

       int status = client.executeMethod(post);

        System.out.println(post.getResponseBodyAsString());

        post.releaseConnection(); 

       //鏌ョ湅cookie淇℃伅

        CookieSpec cookiespec = CookiePolicy.getDefaultSpec();

        Cookie[] cookies = cookiespec.match(LOGON_SITE, LOGON_PORT, "/", false, client.getState().getCookies());

       if (cookies.length == 0) {

           System.out.println("None");   

       } else {

           for (int i = 0; i < cookies.length; i++) {

               System.out.println(cookies[i].toString());   

           }

       }

       //璁塊棶鎵闇鐨勯〉闈ain2.jsp

        GetMethod get = new GetMethod("/main2.jsp");

        client.executeMethod(get);

        System.out.println(get.getResponseBodyAsString());

        get.releaseConnection();

    }

}

5錛?鎻愪氦XML鏍煎紡鍙傛暟

鎻愪氦XML鏍煎紡鐨勫弬鏁板緢綆鍗曪紝浠呬粎鏄竴涓彁浜ゆ椂鍊欑殑ContentType闂錛屼笅闈㈢殑渚嬪瓙婕旂ず浠庢枃浠舵枃浠朵腑璇誨彇XML淇℃伅騫舵彁浜ょ粰鏈嶅姟鍣ㄧ殑榪囩▼錛岃榪囩▼鍙互鐢ㄦ潵嫻嬭瘯Web鏈嶅姟銆?

import java.io.File;

import java.io.FileInputStream;

import org.apache.commons.httpclient.HttpClient;

import org.apache.commons.httpclient.methods.EntityEnclosingMethod;

import org.apache.commons.httpclient.methods.PostMethod;

/**

 * 鐢ㄦ潵婕旂ず鎻愪氦XML鏍煎紡鏁版嵁鐨勪緥瀛?

 */

public class PostXMLClient {

    public static void main(String[] args) throws Exception {

        File input = new File(鈥渢est.xml鈥?;

        PostMethod post = new PostMethod(鈥渉ttp://localhost:8080/httpclient/xml.jsp鈥?;

        // 璁劇疆璇鋒眰鐨勫唴瀹圭洿鎺ヤ粠鏂囦歡涓鍙?

        post.setRequestBody(new FileInputStream(input));

        if (input.length() < Integer.MAX_VALUE)

            post.setRequestContentLength(input.length());

        else           

post.setRequestContentLength(EntityEnclosingMethod.CONTENT_LENGTH_CHUNKED);

        // 鎸囧畾璇鋒眰鍐呭鐨勭被鍨?

        post.setRequestHeader("Content-type", "text/xml; charset=GBK");

        HttpClient httpclient = new HttpClient();

        int result = httpclient.executeMethod(post);

        System.out.println("Response status code: " + result);

        System.out.println("Response body: ");

        System.out.println(post.getResponseBodyAsString());

        post.releaseConnection();

    }

}

6錛?閫氳繃HTTP涓婁紶鏂囦歡

httpclient浣跨敤浜嗗崟鐙殑涓涓狧ttpMethod瀛愮被鏉ュ鐞嗘枃浠剁殑涓婁紶錛岃繖涓被灝辨槸MultipartPostMethod錛岃綾誨凡緇忓皝瑁呬簡鏂囦歡涓婁紶鐨勭粏鑺傦紝鎴戜滑瑕佸仛鐨勪粎浠呮槸鍛婅瘔瀹冩垜浠涓婁紶鏂囦歡鐨勫叏璺緞鍗沖彲錛屼笅闈㈢殑浠g爜鐗囨婕旂ず濡備綍浣跨敤榪欎釜綾匯?

MultipartPostMethod filePost = new MultipartPostMethod(targetURL);

filePost.addParameter("fileName", targetFilePath);

HttpClient client = new HttpClient();

//鐢變簬瑕佷笂浼犵殑鏂囦歡鍙兘姣旇緝澶?鍥犳鍦ㄦ璁劇疆鏈澶х殑榪炴帴瓚呮椂鏃墮棿

client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);

int status = client.executeMethod(filePost);

涓婇潰浠g爜涓紝targetFilePath鍗充負(fù)瑕佷笂浼犵殑鏂囦歡鎵鍦ㄧ殑璺緞銆?

7錛?璁塊棶鍚敤璁よ瘉鐨勯〉闈?

鎴戜滑緇忓父浼?xì)纰板埌杩欐狅L(fēng)殑欏甸潰錛屽綋璁塊棶瀹冪殑鏃跺欎細(xì)寮瑰嚭涓涓祻瑙堝櫒鐨勫璇濇瑕佹眰杈撳叆鐢ㄦ埛鍚嶅拰瀵嗙爜鍚庢柟鍙紝榪欑鐢ㄦ埛璁よ瘉鐨勬柟寮忎笉鍚屼簬鎴戜滑鍦ㄥ墠闈粙緇嶇殑鍩轟簬琛ㄥ崟鐨勭敤鎴瘋韓浠介獙璇併傝繖鏄疕TTP鐨勮璇佺瓥鐣ワ紝httpclient鏀寔涓夌璁よ瘉鏂瑰紡鍖呮嫭錛氬熀鏈佹憳瑕佷互鍙?qiáng)NTLM璁よ瘉銆傚叾涓熀鏈璇佹渶綆鍗曘侀氱敤浣嗕篃鏈涓嶅畨鍏紱鎽樿璁よ瘉鏄湪HTTP 1.1涓姞鍏ョ殑璁よ瘉鏂瑰紡錛岃孨TLM鍒欐槸寰蔣鍏徃瀹氫箟鐨勮屼笉鏄氱敤鐨勮鑼冿紝鏈鏂扮増鏈殑NTLM鏄瘮鎽樿璁よ瘉榪樿瀹夊叏鐨勪竴縐嶆柟寮忋?

涓嬮潰渚嬪瓙鏄粠httpclient鐨凜VS鏈嶅姟鍣ㄤ腑涓嬭澆鐨勶紝瀹冪畝鍗曟紨紺哄浣曡闂竴涓璇佷繚鎶ょ殑欏甸潰錛?

import org.apache.commons.httpclient.HttpClient;

import org.apache.commons.httpclient.UsernamePasswordCredentials;

import org.apache.commons.httpclient.methods.GetMethod;

public class BasicAuthenticationExample {

    public BasicAuthenticationExample() {

    }

    public static void main(String[] args) throws Exception {

        HttpClient client = new HttpClient();

        client.getState().setCredentials(

            "            "realm",

            new UsernamePasswordCredentials("username", "password")

        );

        GetMethod get = new GetMethod("        get.setDoAuthentication( true );

        int status = client.executeMethod( get );

        System.out.println(status+""+ get.getResponseBodyAsString());

        get.releaseConnection();

    }

}

8錛?澶氱嚎紼嬫ā寮忎笅浣跨敤httpclient

澶氱嚎紼嬪悓鏃惰闂甴ttpclient錛屼緥濡傚悓鏃朵粠涓涓珯鐐逛笂涓嬭澆澶氫釜鏂囦歡銆傚浜庡悓涓涓狧ttpConnection 鍚屼竴涓椂闂村彧鑳芥湁涓涓嚎紼嬭闂紝涓轟簡淇濊瘉澶氱嚎紼嬪伐浣滅幆澧冧笅涓嶄駭鐢熷啿紿侊紝httpclient浣跨敤浜嗕竴涓綰跨▼榪炴帴綆$悊鍣ㄧ殑綾伙細(xì) MultiThreadedHttpConnectionManager錛岃浣跨敤榪欎釜綾誨緢綆鍗曪紝鍙渶瑕佸湪鏋勯燞ttpClient瀹炰緥鐨勬椂鍊欎紶鍏ュ嵆鍙紝浠g爜濡備笅錛?pre>MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpClient client = new HttpClient(connectionManager);

 

 

浠ュ悗灝界璁塊棶client瀹炰緥鍗沖彲銆?

鍙傝冭祫鏂欙細(xì)

httpclient棣栭〉錛?nbsp;   http://jakarta.apache.org/commons/httpclient/
鍏充簬NTLM鏄浣曞伐浣滐細(xì)  http://davenport.sourceforge.net/ntlm.html



]]>java IO搴?瀛︿範(fàn)璁板綍http://www.tkk7.com/cherishchen/archive/2007/07/10/129313.html鍑爮瑙傛搗鍑爮瑙傛搗Tue, 10 Jul 2007 04:30:00 GMThttp://www.tkk7.com/cherishchen/archive/2007/07/10/129313.htmlhttp://www.tkk7.com/cherishchen/comments/129313.htmlhttp://www.tkk7.com/cherishchen/archive/2007/07/10/129313.html#Feedback0http://www.tkk7.com/cherishchen/comments/commentRss/129313.htmlhttp://www.tkk7.com/cherishchen/services/trackbacks/129313.html鎵鏈夌被鐨勬牴鎺ュ彛錛欼nputStream/OutputStream

涓銆佸簳灞傜殑榪樻槸瑁呴グ鐨?/b>

1銆佸簳灞傜殑鐩存帴涓庢枃浠剁郴緇熸垨鑰呯‖浠舵墦浜ら亾鐨勭被(鍏呭綋鏁版嵁婧愮殑綾?錛?

鍖呮嫭InputStream鍜孫utPutStream涓ゅぇ綾伙紝鍒嗗埆鐢ㄤ簬杈撳叆鍜岃緭鍑猴紝鏁版嵁婧愬彲浠ユ槸bytes array錛孲tring瀵硅薄錛宖ile鏂囦歡錛宻tream搴忓垪絳夛細(xì)

  • FileInputStream/FileOutputStream
  • ByteArrayInputStream/ByteArrayOutputStream
  • StringBufferInputStream/StringBufferOutputStream

絳夛紝鍏蜂綋鍙傜湅涓嬮潰鐨刯ava io綾誨浘

2銆佸厖褰撹楗板姛鑳界殑io綾?閫氳繃瑁呴グ搴曞眰鐨勭被鏉ュ疄鐜版洿楂樼駭鐨勫姛鑳斤紝緇ф壙鑷狥ilterOutputStream/FilterOutputStream錛屽寘鎷細(xì)

  • BufferedOutputStream/BufferedInputStream
  • Datainputstream/Dataoutputstream

絳夛紝鍏蜂綋鍙傜湅涓嬮潰鐨刯ava io綾誨浘

浣跨敤FilterOutputStream/FilterOutputStream鏃訛紝棣栧厛鍒涘緩涓涓暟鎹簮IO錛岀劧鍚庢牴鎹渶瑕佺殑鍔熻兘鍒涘緩瑁呴グ綾籭o錛屽叾鏋勯犲嚱鏁扮殑鍙傛暟涓哄凡鍒涘緩鐨勬暟鎹簮io銆?

clip_image002

浜屻侀潰鍚戝瓧絎﹁繕鏄潰鍚戝瓧鑺?/b>

鍚屾椂錛宩ava鐨処O浣撶郴鍙堝彲浠ュ垎鎴愶細(xì)inputStream/outputStream鍜宺eader/writer涓ょ被錛?

錛?錛?Reader/Writer鏄潰鍚慤nicode瀛楃鐨勶紙Characters錛?

錛?錛?InputStream/OutputStream鏄洿鎺ラ潰鍚戝瓧鑺傜殑錛坆ytes錛夈?

Reader/Writer緇ф壙浣撶郴涔嬫墍浠ュ瓨鍦紝鏈閲嶈鐨勫師鍥犳槸涓轟簡鍥介檯鍖栵紝鏃у紡I/O stream 鐨勭戶鎵夸綋緋諱粎浠呮敮鎸?-bit byte stream錛岃屼笖鏃犳硶澶勭悊16-bit unicode 瀛楃銆傜敱浜巙nicode琚敤浜庡瓧絎﹀浗闄呭寲錛屾墍浠ュ姞鍏eader/Writer浠ヤ究鍦ㄦ墍鏈夌殑io鍔ㄤ綔涓婃彁渚涘unicode鐨勬敮鎸併?

鍑犱箮鎵鏈夌殑java io stream classes閮芥湁鐩稿簲鐨凴eader鍜學(xué)riter鏉ユ彁渚涘unicode鐨勬敮鎸侊紝浣嗘槸鍦ㄦ煇浜涘満鍚堬紝浣跨敤byte-oriented InputStream鍜孫utPutStream鎵嶆槸姝e彇鐨勬柟娉曪紝鏈鍚堢悊鐨勬柟寮忔槸灝藉彲鑳藉厛灝濊瘯浣跨敤Read鍜學(xué)riter錛屽叾嬈℃墠浣跨敤byte-oriented搴撱?

涓夈佷粠InputStream/OutPutStream鍒癛eader/Writer鐨勮漿鎹?/b>

InputStreamReader鍜孫utputStreamWriter錛屽彲浠ユ妸涓涓互瀛楄妭涓哄鍚戠殑stream杞崲鎴愪竴涓互瀛楃涓哄鍚戠殑stream銆?

Java 1.0 class錛坆yte oriented錛?nbsp;     Java 1.1 class(unicode character oriented)

瑁呴グ鍓嶇殑琛屼負(fù)

InputStream                                                       Reader  杞崲鍣細(xì)InputStreamReader

OutputStreamReader                                          Writer  杞崲鍣細(xì)OutputStreamWriter

FileInputSream                                                   FileOutputStream

FileReader                                                          FileWriter

StringBufferInputStream                                    StringReader/StringWriter                                    

ByteArrayInputStream                                        ByteArrayOutputStream                 

CharArrayReader                                                CharArrayWriter

瑁呴グ鍚庣殑琛屼負(fù)

BufferedInputStream                                          BufferedOutputStream

BufferedReader                                                  BufferedWriter

PrintStream                                                        PrintWriter

鍥涖佺ず渚?/b>

DataInputStream鍜孌ataOutputStream

Java涓櫎浜嗕簩榪涘埗鏂囦歡鍜屼嬌鐢ㄦ枃鏈枃浠跺榪樻湁鍩轟簬Data鐨勬暟鎹搷浣滐紝榪欓噷鐨凞ata鎸囩殑鏄疛ava鐨勫熀鏈暟鎹被鍨嬪拰String銆傚熀鏈暟鎹被鍨嬪寘鎷琤yte銆乮nt銆乧har銆乴ong銆乫loat銆乨ouble銆乥oolean鍜宻hort銆?/b>

渚嬪瓙錛?/b>

protected void connect (Socket socket)

throws IOException, SocketException

{

this.socket = socket;

applyTimeout();

serverIn = new DataInputStream (

new BufferedInputStream (socket.getInputStream ())

);

serverOut = new DataOutputStream(

new BufferedOutputStream(socket.getOutputStream(), 2048)

);

usable = true;

cnt[CONNECT]++;

setChanged();

notifyObservers();

}

鍦―ataInputStream鍜孌ataOutputStream涓や釜綾諱腑鐨勬柟娉曢兘寰堢畝鍗曪紝鍩烘湰緇撴瀯涓簉eadXXXX()鍜寃riteXXXX()鍏朵腑XXXX浠h〃鍩烘湰鏁版嵁綾誨瀷鎴栬匰tring銆?/p>

]]>
鐗涘垁灝忚瘯-鐢╦dom鏉ヨВ鏋恆nt鐨刡uild鏂囦歡http://www.tkk7.com/cherishchen/archive/2007/07/05/128235.html鍑爮瑙傛搗鍑爮瑙傛搗Thu, 05 Jul 2007 01:11:00 GMThttp://www.tkk7.com/cherishchen/archive/2007/07/05/128235.html/**
* 瀛︿範(fàn)jdom鎿嶄綔xml鐨勪範(fàn)浣滐細(xì)瑙f瀽ant鐨刡uild鏂囦歡錛岀洰鐨勬槸寰楀埌target鐨勬墽琛岄『搴?br>*
*/
import
 java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

public class AntFileParser {
    
private static Map<String, Element> targetMap;

    
/**
     * 
@param args
     
*/
    
public static void main(String[] args) {
        String xmlfile 
= "xmlfile/aaa.xml";
        Document doc;
        String finalTarget 
= "run";
        
try {
            doc 
= build(xmlfile);
        } 
catch (JDOMException e) {
            
throw new RuntimeException("parse error" + e, e);
        } 
catch (IOException e) {
            
throw new RuntimeException("parse error" + e, e);
        }

        generateTargetNameMap(doc);
        
// 棣栧厛灝嗘渶緇堜換鍔″叆鏍?/span>
        Stack<String> stack = new Stack<String>();
        stack.push(finalTarget);
        
// 璁$畻鍏朵粬浠誨姟鐨勬墽琛岄『搴?/span>
        getExecuteOrder(findElementByAttributeName(finalTarget), stack);
        System.out.print(
"鎵ц欏哄簭錛?nbsp; ");
        
while (!stack.isEmpty()) {
            System.out.print(stack.pop() 
+ " ");
        }

    }

    
public static Document build(String file) throws JDOMException, IOException {
        SAXBuilder b 
= new SAXBuilder();
        Document doc 
= b.build(new File(file));
        
return doc;
    }

    
/**
     * 鑾峰彇鎵鏈塼arget鍏冪礌
     * 
     * 
@param doc
     * 
@return
     
*/
    
public static List getTarget(Document doc) {
        
return doc.getRootElement().getChildren("target");
    }

    
/**
     * 鑾峰彇鎸囧畾鍏冪礌鐨勬墍鏈変緷璧?br>     * 
     * 
@param element
     * 
@return
     
*/
    
public static String[] getDepents(Element element) {
        String depends 
= element.getAttribute("depends").getValue();
        
return depends.split(",");
    }

    
/**
     * 浣跨敤閫掑綊鐨勬柟娉曟煡鎵炬墽琛岄『搴?br>     * 
     * 
@param element
     * 
@param stack
     
*/
    
public static void getExecuteOrder(Element element, Stack<String> stack) {
        String cur;
        
if (element.getAttribute("depends"== null) {
            
// 宸茬粡鎵懼埌浜嗙涓涓換鍔★紝閫鍑?/span>
            return;
        } 
else {
            String[] depends 
= getDepents(element);
            cur 
= depends[0];
            
if (depends.length != 1) {
                
// 瀛樺湪澶氫釜渚濊禆浠誨姟錛屽彲鑳芥湁涓ょ鎯呭喌錛?br>                // 錛?錛夊涓換鍔′箣闂存湁渚濊禆鍏崇郴錛屽垯榪斿洖渚濊禆鏈澶х殑浠誨姟錛?br>                // 錛?錛夊涓換鍔′箣闂存病鏈変緷璧栧叧緋伙紝鍒欒繑鍥炲叏閮ㄤ緷璧栵紝鐢ㄩ楀彿鍒嗛殧
                cur = getmaxDependence(depends);
            }
            String[] curs 
= cur.split(",");
            
// 濡傛灉瀛樺湪騫惰浠誨姟涓斿茍琛屼換鍔′箣闂存病鏈変簰鐩鎬緷璧栵紝鍒欎竴騫舵斁鍏ュ爢鏍堬紝鏃犳墍璋撻『搴?/span>
            for (String string : curs) {
                element 
= findElementByAttributeName(string);
                
// 媯鏌ユ槸鍚﹀凡緇忓叆鏍?/span>
                if (!stack.contains(element.getAttributeValue("name")))
                    stack.push(element.getAttributeValue(
"name"));
            }
            
// 閫掑綊
            getExecuteOrder(element, stack);
        }

    }

    
/**
     * 浠庣紦瀛樼殑Map涓紝渚濇嵁target鍏冪礌鐨刵ame灞炴ф煡鎵総arget鍏冪礌
     * 
     * 
@param name
     * 
@return
     
*/
    
public static Element findElementByAttributeName(String name) {
        
return targetMap.get(name);
    }

    
/**
     * 灝唗arget鍏冪礌鍜屽叾name灞炴х紦瀛樺埌map涓?br>     * 
     * 
@param doc
     
*/
    
public static void generateTargetNameMap(Document doc) {
        List targetList 
= getTarget(doc);
        targetMap 
= new HashMap<String, Element>();
        
for (Object object : targetList) {
            Element ele 
= (Element) object;
            String name 
= ele.getAttributeValue("name");
            targetMap.put(name, ele);
        }
    }

    
public static String getmaxDependence(String[] depends) {
        
int size = depends.length;
        String target 
= "";
        
// 淇濆瓨姣忎竴涓換鍔″鍏朵粬浠誨姟鐨勫瓨鍦ㄤ緷璧栧叧緋葷殑嬈℃暟
        int[] counts = new int[size];
        
//
        for (int i = 0; i < size; i++) {
            Element cur 
= findElementByAttributeName(depends[i]);
            
// 灝嗘暟緇勮漿鎹㈡垚ArrayList
            List list = arrayToList(getDepents(cur));
            
for (int j = i + 1; j < size; j++) {
                
// 媯鏌ュ綋鍓嶄換鍔″depends鏁扮粍涓殑鍏朵粬浠誨姟鏄惁瀛樺湪渚濊禆
                if (list.contains(depends[j])) {
                    counts[i]
++;
                }
            }
        }
        
// 鑾峰彇鏈澶т緷璧?/span>
        int max = 0;
        
for (int a : counts) {
            
if (max < a)
                max 
= a;
        }
        
// 濡傛灉鏈澶т緷璧栦負(fù)0錛屽垯璇存槑depends涓殑浠誨姟涔嬮棿娌℃湁浜掔浉渚濊禆錛屼負(fù)騫惰浠誨姟錛岃漿鎹㈤楀彿鍒嗛殧榪斿洖
        if (max == 0) {
            
for (int i = 0; i < size; i++) {
                target 
= target + depends[i] + ",";
            }
            
// 闄ゅ幓鏈鍚庝竴涓楀彿
            target = target.substring(0, target.length() - 1);
            
return target;
        }
        
// 鍚﹀垯錛屼換鍔′箣闂村瓨鍦ㄤ緷璧栵紝鍙栨渶澶т緷璧?/span>
        for (int i = 0; i < size; i++) {
            
if (counts[i] == max)
                target 
= depends[i];
        }
        
return target;
    }

    
public static List<String> arrayToList(String[] array) {
        ArrayList
<String> list = new ArrayList<String>();
        
for (String string : array) {
            list.add(string);
        }
        
return list;
    }

}

鐢ㄥ埌鐨剎ml鏂囦歡

<?xml version="1.0" encoding="UTF-8"?>
<project name="srping_study" default="run">

    
<property name="src" value="src" />
    
<property name="bin" value="bin" />
    
<property name="test" value="test" />
    
<property name="run.classpath" value="bin" />
    
<property name="lib" value="lib" />
    
<property name="xmlfile" value="xmlfile" />

    
<path id="spring.lib">
        
<pathelement path="${lib}" />
        
<fileset dir="${lib}" includes="*.jar" />
    
</path>

    
<target name="clear">
        
<delete dir="${bin}" quiet="true" />
    
</target>

    
<target name="compile" depends="clear">
        
<mkdir dir="bin" />
        
<javac destdir="${run.classpath}" srcdir="${src}" classpathref="spring.lib">
        
</javac>
        
<copy todir="${run.classpath}">
            
<fileset dir="${xmlfile}">
                
<include name="*.xml" />
                
<include name="*.properties" />
            
</fileset>
        
</copy>
    
</target>

    
<target name="deploy" depends="compile">
        
<java classname="org.chen.spring_study.HibernateUtil" classpathref="spring.lib">
            
<classpath path="${run.classpath}" />
        
</java>
    
</target>
    
    
<target name="deploy1" depends="deploy">
            
<java classname="org.chen.spring_study.HibernateUtil" classpathref="spring.lib">
                
<classpath path="${run.classpath}" />
            
</java>
        
</target>

    
<target name="test" depends="compile">
        
<java classname="org.chen.spring_study.transaction.programmic.ProgramicCodingTrans" classpathref="spring.lib">
            
<classpath path="${run.classpath}" />
        
</java>
    
</target>
    


    
<target name="run" depends="test,deploy,deploy1">
        
<java classname="org.chen.spring_study.transaction.declaretrans.DeclareClient" classpathref="spring.lib">
            
<classpath path="${run.classpath}" />
        
</java>
    
</target>
</project>


]]>
Jdom 甯哥敤APIhttp://www.tkk7.com/cherishchen/archive/2007/07/04/128138.html鍑爮瑙傛搗鍑爮瑙傛搗Wed, 04 Jul 2007 08:35:00 GMThttp://www.tkk7.com/cherishchen/archive/2007/07/04/128138.htmlhttp://www.tkk7.com/cherishchen/comments/128138.htmlhttp://www.tkk7.com/cherishchen/archive/2007/07/04/128138.html#Feedback0http://www.tkk7.com/cherishchen/comments/commentRss/128138.htmlhttp://www.tkk7.com/cherishchen/services/trackbacks/128138.html浣跨敤Jdom錛屾搷浣渪ml浠庢鍙樺緱鏂逛究錛宆_^

涓銆佸垱寤篨ML鏂囦歡

Document doc = new Document(new Element("rootElement"))

鎴栬?

Document doc = new Document();
// 鏍瑰厓绱?/p>

 Element root = new Element("persons");
 doc.addContent(root);

// add person
Element person = new Element("person").setText("test1");
root.addContent(person);

//add person 2
person = new Element("person").setText("test2");
root.addContent(person);

 

鍙﹀涓縐嶆柟寮忥細(xì)

Document doc = new Document(new Element("family")
.addContent(new Element("mom"))
.addContent(new Element("dad").addContent("kidOfDad")));

浜屻佽В鏋怷ML鏂囦歡

   涓鑸岃█錛屼嬌鐢╫rg.jdom.input.SAXBuilder鏇村揩錛屾帹鑽愪嬌鐢紝鑰宱rg.jdom.input.DOMBuilder閫傜敤浜庡凡緇忓瓨鍦―OM瀵硅薄鐨勫満鍚堛?

SAXBuilder b = new SAXBuilder();
            // Create the document
Document doc = b.build(new File(xmlfilename));

  • 鑾峰彇鏍瑰厓绱狅細(xì)Element webapp = doc.getRootElement();
  • 鑾峰彇瀛愯妭鐐癸紙鏀寔namespace錛夛細(xì)

// Get a List of direct children as Elements
List allChildren = element.getChildren();

// Get all direct children with a given name
List namedChildren = element.getChildren("name");

// Get the first kid with a given name
Element kid = element.getChild("name");

  • 澧炲姞/鍒犻櫎瀛愯妭鐐癸紝鍙互鍍忔搷浣淟ist瀵硅薄涓鏍鋒搷浣滃瓙鑺傜偣闆嗗悎錛屽綋鐒朵篃鍙互浠ヤ紶緇熺殑鏂瑰紡鏉ユ搷浣?/li>

List allChildren = element.getChildren();
// Remove the fourth child
allChildren.remove(3);
// Remove all children named "jack"
allChildren.removeAll(element.getChildren("jack"));

鎴栬?br /> element.removeChildren("jack");
// Add a new child
allChildren.add(new Element("jane"));

鎴栬?br /> element.addContent(new Element("jane"));
// Add a new child in the second position
allChildren.add(1, new Element("second"));

  • 璇誨彇/璁劇疆灞炴?/li>

// 璇誨彇灞炴э細(xì)

String value =table.getAttributeValue("width");// table 鏄痚lement
// 涔熷彲浠ュ湪璇誨彇灞炴х殑鍚屾椂榪涜綾誨瀷杞崲
try {
value =table.getAttribute("border").getIntValue();
}
catch (DataConversionException e) { }

// 璁劇疆灞炴?

// Add an attribute
table.addAttribute("vspace", "0");
// Add an attribute more formally 姣旇緝姝e紡鐨勫啓娉?br /> table.addAttribute(new Attribute("name", "value"))
// Remove an attribute
table.removeAttribute("border");
// Remove all attributes 縐婚櫎鎵鏈夊睘鎬?br /> table.getAttributes().clear();

  • 鑾峰彇鍏冪礌鐨勫唴瀹?/li>

姣斿<description>A cool demo</description>錛屽垯鍙互鐩存帴鑾峰彇鍐呭

String content = element.getText();

// 縐婚櫎澶氫綑鐨勭┖鐧斤紝瀛楃涓插墠鍚庣殑絀虹櫧錛屼笉浼?xì)绉婚櫎瀛椊W︿覆鍐呴儴鐨勭┖鐧?

element.getTextNormalize();

  • 璁劇疆鍏冪礌鐨勫唴瀹?/li>

// This blows away all current content
element.setText("A new description");

//Special characters are interpreted correctly: 鐗規(guī)畩瀛楃鍙互琚紜湴杞箟

element.setText("<xml> content");

// 鍒涘緩cdata鍏冪礌

element.addContent(new CDATA("<xml> content"));

涓夈佽緭鍑篨ML

XMLOutputter 綾葷敤鏉ュ疄鐜癤ML鏂囦歡鐨勮緭鍑猴紝鍦ㄥ垱寤虹殑鏃跺欓渶瑕佷竴涓狥ormat瀵硅薄鏉ユ牸寮忓寲XML鏂囦歡錛孎ormat瀵硅薄鏄竴涓伐鍘傜被錛屾彁渚涘嚑涓潤鎬佺殑宸ュ巶鏂規(guī)硶鏉ユ彁渚涗竴浜涘父瑙勭殑XML鏍煎紡錛屾瘮濡俫etPrettyFormat()錛?

XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
        try {
            outputter.output(doc, new FileOutputStream(new File("xmlfile/persons.xml")));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

 

鍥涖亁ml Namespace鐨勬敮鎸?/h2>
  • 鑾峰彇鍚嶇┖闂?/li>

Namespace xhtml = Namespace.getNamespace("xhtml", “http://www.w3.org/1999/xhtml”);

  • Namespace 瀵硅薄鍙互浣滀負(fù)Element 鍜孉ttribute鐨勫ぇ澶氭暟鏂規(guī)硶鐨勫彲閫夊弬鏁幫細(xì)

List kids = element.getChildren("p", xhtml);
Element kid = element.getChild("title", xhtml);
Attribute height = element.getAttribute("height", xhtml);

闄勫綍錛欽ava涓媂ML緙栫▼鎺ュ彛姣旇緝錛欴OM SAX JDOM JAXP錛堢綉緇滆杞斤級

涓銆丏OM 錛堟枃。瀵硅薄妯″瀷锛
涓?XML 鏂囨。鐨勫凡瑙f瀽鐗堟湰瀹氫箟浜嗕竴緇勬帴鍙c傝В鏋愬櫒璇誨叆鏁翠釜鏂囨。錛岀劧鍚庢瀯寤轟竴涓┗鐣欏唴瀛樼殑鏍?wèi)缁撴瀯锛岀劧鍚庝唬鐮仦鍙互鋴社?DOM 鎺ュ彛鏉ユ搷浣滆繖涓爲(wèi)緇撴瀯銆?br /> 浼樼偣錛氭暣涓枃。鏍(wèi)鍦ㄥ唴瀛樹腑錛屼究浜庢搷浣滐紱鏀寔鍒犻櫎銆佷慨鏀廣侀噸鏂版帓鍒楃瓑澶氱鍔熻兘錛?br /> 緙虹偣錛氬皢鏁翠釜鏂囨。璋冨叆鍐呭瓨錛堝寘鎷棤鐢ㄧ殑鑺傜偣錛夛紝嫻垂鏃墮棿鍜岀┖闂達(dá)紱
浣跨敤鍦哄悎錛氫竴鏃﹁В鏋愪簡鏂囨。榪橀渶澶氭璁塊棶榪欎簺鏁版嵁錛?br /> 紜歡璧勬簮鍏呰凍錛堝唴瀛樸丆PU錛?br />  浜屻丼AX
涓鴻В鍐矰OM鐨勯棶棰橈紝鍑虹幇浜哠AX銆?br /> SAX 錛屼簨浠墮┍鍔ㄣ傚綋瑙f瀽鍣ㄥ彂鐜板厓绱犲紑濮嬨佸厓绱犵粨鏉熴佹枃鏈佹枃。鐨勫紑濮嬫垨緇撴潫絳夋椂錛屽彂閫佷簨浠訛紝紼嬪簭鍛樼紪鍐欏搷搴旇繖浜涗簨浠剁殑浠g爜錛屼繚瀛樻暟鎹?br /> 浼樼偣錛氫笉鐢ㄤ簨鍏堣皟鍏ユ暣涓枃。锛屽崰鐢ㄨ祫婧悶畱锛
SAX瑙f瀽鍣ㄤ唬鐮佹瘮DOM瑙f瀽鍣ㄤ唬鐮佸皬錛岄備簬Applet錛屼笅杞?br /> 緙虹偣錛氫笉鏄寔涔呯殑錛涗簨浠惰繃鍚庯紝鑻ユ病淇濆瓨鏁版嵁錛岄偅涔堟暟鎹氨涓簡錛?br /> 鏃犵姸鎬佹э紱浠庝簨浠朵腑鍙兘寰楀埌鏂囨湰錛屼絾涓嶇煡璇ユ枃鏈睘浜庡摢涓厓绱狅紱
浣跨敤鍦哄悎錛欰pplet;
鍙渶XML鏂囨。鐨勫皯閲忓唴瀹癸紝寰堝皯鍥炲ご璁塊棶錛?br /> 鏈哄櫒鍐呭瓨灝戯紱
 涓夈丣DOM
涓哄噺灝慏OM銆丼AX鐨勭紪鐮侀噺錛屽嚭鐜頒簡JDOM錛?br /> 浼樼偣錛?0-80鍘熷垯錛屾瀬澶у噺灝戜簡浠g爜閲?br /> 浣跨敤鍦哄悎錛氳瀹炵幇鐨勫姛鑳界畝鍗曪紝濡傝В鏋愩佸垱寤虹瓑錛屼絾鍦ㄥ簳灞傦紝JDOM榪樻槸浣跨敤SAX錛堟渶甯哥敤錛夈丏OM銆乆anan
鍥涖丣AXP
涓哄涓猉ML瑙f瀽鍣ㄦ彁渚涗簡緇熶竴緙栫▼鎺ュ彛
鏇存崲瑙f瀽鍣紝涓嶇敤鏇存敼浠g爜
浣跨敤鍦哄悎錛氳嫢涓嶇敤Jdom錛屼竴鑸緩璁嬌鐢↗APX錛屽皢浠g爜涓庡悇縐嶈В鏋愬櫒鐨勫疄鐜扮粏鑺傞殧紱匯?/p>



]]>The JDOM Philosophyhttp://www.tkk7.com/cherishchen/archive/2007/07/04/128048.html鍑爮瑙傛搗鍑爮瑙傛搗Wed, 04 Jul 2007 03:19:00 GMThttp://www.tkk7.com/cherishchen/archive/2007/07/04/128048.htmlhttp://www.tkk7.com/cherishchen/comments/128048.htmlhttp://www.tkk7.com/cherishchen/archive/2007/07/04/128048.html#Feedback0http://www.tkk7.com/cherishchen/comments/commentRss/128048.htmlhttp://www.tkk7.com/cherishchen/services/trackbacks/128048.htmlThe JDOM Philosophy

• JDOM should be straightforward for Java programmers
– Use the power of the language (Java 2)
– Take advantage of method overloading, the Collections APIs, reflection, weak references
– Provide conveniences like type conversions


• JDOM should hide the complexities of XML wherever possible
An Element has content, not a child Text node with content
– Exceptions should contain useful error messages
– Give line numbers and specifics, use no SAX or DOM specifics

• JDOM should integrate with DOM and SAX
– Support reading and writing DOM documents and SAX events
– Support runtime plug-in of any DOM or SAX parser
– Easy conversion from DOM/SAX to JDOM
– Easy conversion from JDOM to DOM/SAX


• JDOM should stay current with the latest XML standards
– DOM Level 2, SAX 2.0, XML Schema


• JDOM does not need to solve every problem
– It should solve 80% of the problems with 20% of the effort
– We think we got the ratios to 90% / 10%

JDOM consists of five packages

 

image

 

The org.jdom.input Package


• Classes for reading XML from existing sources:
– DOMBuilder
– SAXBuilder
• Also, outside contributions in jdom-contrib:
– ResultSetBuilder
– SpitfireBuilder
• New support for JAXP-based input
– Allows consistency across applications
– Builders pick up JAXP information and user automatically
– Sets stage for JAXP version.next

 

The org.jdom.output Package


Classes for writing XML to various forms of output:
– DOMOutputter
– SAXOutputter
– XMLOutputter
Also, outside contributions in jdom-contrib:
– JTreeOutputter

 

org.jdom.transform

• TRaX is now supported in org.jdom.transform
– Supports XSLT transformations
– Defines Source and Result interfaces
– JDOMSource
– JDOMResult

 

General Program Flow


• Normally XML Document -> SAXBuilder ->XMLOutputter

image




瀹屾暣鐨刾df涓嬭澆鍦板潃錛?span style="font-weight: bold;">JDOM: How It Works,and How It Opened the Java Processby Jason Hunter

http://www.tkk7.com/Files/cherishchen/JDOM%20How%20It%20Works.zip



]]>
涓瀹朵箣璦--Java寮傚父澶勭悊http://www.tkk7.com/cherishchen/archive/2007/07/04/128014.html鍑爮瑙傛搗鍑爮瑙傛搗Wed, 04 Jul 2007 01:18:00 GMThttp://www.tkk7.com/cherishchen/archive/2007/07/04/128014.htmlhttp://www.tkk7.com/cherishchen/comments/128014.htmlhttp://www.tkk7.com/cherishchen/archive/2007/07/04/128014.html#Feedback0http://www.tkk7.com/cherishchen/comments/commentRss/128014.htmlhttp://www.tkk7.com/cherishchen/services/trackbacks/128014.htmlJava寮傚父涓烘垜浠彁渚涗簡涓鑷寸殑璇嗗埆鍜屽鐞嗙▼搴忛敊璇殑鏈哄埗錛屾湁鏁堢殑寮傚父澶勭悊鑳藉寮虹▼搴忕殑鍋ュ.鎬у拰鏄撲簬璋冭瘯鎬с?/span>

棣栧厛榪樻槸閲嶆俯涓?/span>java鐨勫紓甯鎬綋緋葷粨鏋勶紝濡傚浘鎵紺猴紝鎵鏈夊紓甯哥殑鏍規(guī)槸Throwable錛屽紓甯稿張鍒嗕負(fù)checked exception鍜?/span>unchecked exception錛?/span>RuntimeException灝辨槸灞炰簬unchecked exception錛?/span>JVM 涓鏃︽崟鎹夊埌unchecked exception 灝變細(xì)緇堟褰撳墠榪愯鐨勭▼搴忥紝騫跺湪console涓墦鍑洪敊璇俊鎭?/span>

 

Java exception hierarchyption hierarchy

涓銆?/span>Unchecked exceptions VS Checked exceptions

 涓嬭〃鍒楀嚭浣跨敤涓ょ寮傚父鐨勫満鍚堬細(xì)

Client's reaction when exception happens

Exception type

Client code cannot do anything

Make it an unchecked exception

Client code will take some useful recovery action based on information in exception

Make it a checked exception

 榪欎釜鏂歸潰鐨勪緥瀛?/span>hibernate灝辨槸涓涓紝鍦?/span>hibernate2涓紝HibernateException榪樻槸checked exceptions錛屼絾鏄埌浜?/span>hibernate3涓氨鎴愪簡unchecked exceptions錛屽洜涓哄浜庢暟鎹簱鎿嶄綔鏉ヨ錛屼竴鏃﹀嚭鐜板紓甯革紝灝辨槸姣旇緝涓ラ噸鐨勯敊璇紝鑰屼笖鍦?/span>client绔熀鏈笂鏄棤鑳戒負(fù)鍔涚殑錛屼嬌鐢?/span>unchecked exceptions鏇村姞鍚堥傘?/span>

鍙﹀錛?/span>unchecked exceptions鐨勪紭鐐瑰湪浜庝笉寮鴻揩瀹㈡埛绔唬鐮佹樉寮忓湴澶勭悊浠栦滑錛屽紓甯稿彲浠ヤ竴鐩村線涓婁紶閫掞紙闄ら潪闇瑕佽漿鍖栧紓甯革紝鍚﹀垯寮傚父涓嶉渶瑕佸湪涓棿琚崟鎹夛紝鑺傜渷浜嗗緢澶氱殑try{}catch()錛屼唬鐮佹洿鍔犵畝媧侊級錛岀洿鍒頒綘鎯蟲崟鎹夊鐞嗕粬浠紝錛堟湁浜轟細(xì)闂紝濡備綍涓嶅己鍒跺鎴風(fēng)澶勭悊浠栦滑錛屾瘮濡傚儚checked exceptions榪欐牱錛屼笉澶勭悊灝辨槸璇硶閿欒錛屽浣曚繚璇佸紓甯歌兘澶熷緱鍒板鐞嗗憿錛熷湪榪欑偣涓婏紝java鎻愪緵鐨勫畬鍠勭殑鏂囨。鏈哄埗錛岄氳繃API瀹㈡埛绔▼搴忓憳鍙互寰堟柟渚垮湴鐭ラ亾浠栬皟鐢ㄧ殑鏂規(guī)硶鍙兘浼?xì)鎶涘囖Z粈涔堝紓甯革紝涓涓礋璐d漢鐨勭▼搴忓憳灝卞簲璇ュ鍏惰繘琛?/span>catch鍜屽鐞嗭級錛?/span>Java API鎻愪緵浜嗗緢澶氱殑unchecked exceptions錛屾瘮濡?/span>NullPointerException, IllegalArgumentException, and IllegalStateException錛屼嬌鐢?span lang="EN-US">java鎻愪緵鐨勬爣鍑嗙殑unchecked exceptions鏄煎緱鎺ㄨ崘鐨勶紝榪欐牱鐨勫ソ澶勫湪浜庝嬌浠g爜鏇村姞綆媧佸茍鍙互鍑忓皯浠g爜瀵瑰唴瀛樼殑鍗犵敤銆?/span>

浜屻?/span>Java寮傚父鐨勬帹榪熷鐞?/span>

Java寮傚父搴旇灝藉彲鑳藉湴鎺ㄨ繜澶勭悊錛岄櫎闈炶杞寲寮傚父錛岄噸鏂版姏鍑猴紝鍚﹀垯鏈濂戒笉瑕佸鐞嗭紝鑰屾槸鐣欑粰鏈鍚庤兘澶熷鐞嗗紓甯哥殑鍦版柟銆?/span>

閫氳繃涓烘柟娉曟坊鍔?/span>throws澹版槑錛屽彲浠ュ皢澶勭悊寮傚父鐨勮矗浠諱紶閫掑埌鏇撮珮鐨勫眰嬈°傚湪澹版槑鍝簺闇瑕佹姏鍑虹殑鏃跺欙紝搴旇灝藉彲鑳藉湴璇︾粏銆傝繖鏍峰仛鐨勭洰鐨勬槸鍙互鍦?/span>API涓緇嗗湴琛ㄨ堪鍑鴻鏂規(guī)硶鍙兘浼?xì)鍑虹幇鐨勫紓甯稿Q屼粠鑰岃璋冪敤璇ユ柟娉曠殑clinet紼嬪簭鍛樺仛濂藉鐞嗗紓甯哥殑鍑嗗錛屾瘮濡傚浜庝唬鐮侀氳繃throws璇彞璇︾粏鍦板0鏄庝簡鍙兘浼?xì)鎶涘嚭鐨勫紓甯稿Q岃繖鏍瘋皟鐢ㄨ鏂規(guī)硶鐨勭▼搴忓憳灝變細(xì)鐭ラ亾灝嗕細(xì)鏈変粈涔堟牱鐨勫紓甯鎬細(xì)鍙戠敓銆?/span>

public void readPreferences(String filename)

    
throws IllegalArgumentException,

          FileNotFoundException, IOException
{

    
if (filename == null)
    {

        
throw new IllegalArgumentException

                        (
"filename is null");

    }  
//if
    
//
    InputStream in = new FileInputStream(filename);

    
//
}

浠庤娉曚笂璁詫紝IllegalArgumentException鏄?/span>unckecked exception 鏄笉闇瑕佸0鏄庣殑錛屼絾鏄負(fù)浜嗕粠鏂囨。鐨勮搴﹁冭檻錛屾渶濂借繕鏄姞涓婏紝榪欐牱鍙互璁╄皟鐢ㄨ繖涓柟娉曠殑紼嬪簭鍛樼煡閬擄紝榪欎釜鏂規(guī)硶浼?xì)鍙兘鎶涘國櫙ュ紓甯稿Q岄渶瑕佸姞浠ユ崟鎹夊拰澶勭悊銆?/span>

 

涓夈佸紓甯哥殑澶勭悊

涓嶇濡備綍錛屾渶緇堢▼搴忚偗瀹氭槸瑕佸寮傚父榪涜澶勭悊鐨勶紝鍚﹀垯浼?xì)瀵艰嚧涓嵓嫯瀹氭儏鍐电殑鍙戠敓锛屼絾鏄夋嫨寮傚父澶勭悊鐨勪綅緗嵈鏄湁鎶宸х殑錛岄氬父瑕佷箞鏄▼搴忓湪榪欎簺鍦版柟浠庡紓甯鎬腑鎭㈠銆佺戶緇墽琛屼笖涓嶄細(xì)瀵艱嚧榪涗竴姝ュ紓甯哥殑鍙戠敓錛岃涔堟槸鍦ㄨ繖浜涘湴鏂硅兘涓虹敤鎴峰弽棣堢壒瀹氱殑淇℃伅錛屾瘮濡傦紝濡備綍閬垮厤寮傚父鐨勫彂鐢熸垨鑰呭浣曚粠寮傚父涓仮澶嶃傚洜姝わ紝瀵逛簬鏈夌敤鎴風(fēng)晫闈㈠眰鐨勭▼搴忥紝灝嗗紓甯哥殑鎹曟崏鍜屽鐞嗘帹榪熷埌UI灞傛槸鏈夊ソ澶勭殑錛屽湪UI灞傚彲浠ヤ嬌鐢ㄥ璇濇鎴栬呭叾浠栨柟寮忔彁紺虹敤鎴峰嚭鐜板紓甯搞?/span>
 

鍙傝冩枃鐚?/span>

Best Practices for Exception Handling by Gunjan Doshi

Three Rules for Effective Exception Handling by Jim Cushing



]]>
Dijkstra綆楁硶-瀵繪壘鏈夊悜鍥句腑鏈鐭礬寰?/title><link>http://www.tkk7.com/cherishchen/archive/2007/07/03/127882.html</link><dc:creator>鍑爮瑙傛搗</dc:creator><author>鍑爮瑙傛搗</author><pubDate>Tue, 03 Jul 2007 08:28:00 GMT</pubDate><guid>http://www.tkk7.com/cherishchen/archive/2007/07/03/127882.html</guid><wfw:comment>http://www.tkk7.com/cherishchen/comments/127882.html</wfw:comment><comments>http://www.tkk7.com/cherishchen/archive/2007/07/03/127882.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.tkk7.com/cherishchen/comments/commentRss/127882.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/cherishchen/services/trackbacks/127882.html</trackback:ping><description><![CDATA[<p><strong>Dijkstra綆楁硶</strong>鏄敱鑽峰叞璁$畻鏈虹瀛﹀鑹懼吂鏍?#183;榪鏂交鍙戠幇鐨勩傜畻娉曡В鍐崇殑鏄湁鍚戝浘涓渶鐭礬寰勯棶棰樸?/p> <p>涓句緥鏉ヨ錛屽鏋滃浘涓殑欏剁偣琛ㄧず鍩庡競錛岃岃竟涓婄殑鏉冮噸琛ㄧず钁楀煄甯傞棿寮杞﹁緇忕殑璺濈銆?Dijkstra綆楁硶鍙互鐢ㄦ潵鎵懼埌涓や釜鍩庡競涔嬮棿鐨勬渶鐭礬寰勩?/p> <p>Dijkstra綆楁硶鐨勮緭鍏ュ寘鍚簡涓涓湁鏉冮噸鐨勬湁鍚戝浘<em>G</em>錛屼互鍙?qiáng)G涓殑涓涓潵婧愰《鐐?em>S</em>銆?鎴戜滑浠?em>V</em>琛ㄧず<em>G</em>涓墍鏈夐《鐐圭殑闆嗗悎銆傚浘涓殑姣忎竴涓竟錛岄兘鏄袱涓《鐐規(guī)墍褰㈡垚鐨勬湁搴忓厓绱犲銆?<em>u</em>,<em>v</em>)琛ㄧず浠庨《鐐?em>u</em>鍒?em>v</em>鏈夎礬寰勭浉榪炪?鍋囪<em>E涓?/em>鎵鏈夎竟鐨勯泦鍚堬紝鑰岃竟鐨勬潈閲嶅垯鐢辨潈閲嶅嚱鏁?em>w</em>: <em>E</em> → [0, ∞]瀹氫箟銆?鍥犳錛?em>w</em>(<em>u</em>,<em>v</em>)灝辨槸浠庨《鐐?em>u</em>鍒伴《鐐?em>v</em>鐨勯潪璐熻姳璐瑰?cost)銆?杈圭殑鑺辮垂鍙互鎯沖儚鎴愪袱涓《鐐逛箣闂寸殑璺濈銆備換涓ょ偣闂磋礬寰勭殑鑺辮垂鍊鹼紝灝辨槸璇ヨ礬寰勪笂鎵鏈夎竟鐨勮姳璐瑰兼誨拰銆?宸茬煡鏈?em>V</em>涓湁欏剁偣<em>s</em>鍙?em>t</em>錛孌ijkstra綆楁硶鍙互鎵懼埌<em>s</em>鍒?em>t</em>鐨勬渶浣庤姳璐硅礬寰?i.e. 鏈鐭礬寰?銆?榪欎釜綆楁硶涔熷彲浠ュ湪涓涓浘涓紝鎵懼埌浠庝竴涓《鐐?em>s</em>鍒頒換浣曞叾浠栭《鐐圭殑鏈鐭礬寰勩?/p> <br> <h3>綆楁硶鎻忚堪</h3> <p>  榪欎釜綆楁硶鏄氳繃涓烘瘡涓《鐐?em>v</em>淇濈暀鐩墠涓烘鎵鎵懼埌鐨勪粠s鍒皏鐨勬渶鐭礬寰勬潵宸ヤ綔鐨勩傚垵濮嬫椂錛屾簮鐐箂鐨勮礬寰勯暱搴﹀艱璧嬩負(fù)0錛?em>d[s]</em>=0錛夛紝 鍚屾椂鎶婃墍鏈夊叾浠栭《鐐圭殑璺緞闀垮害璁句負(fù)鏃犵┓澶э紝鍗寵〃紺烘垜浠笉鐭ラ亾浠諱綍閫氬悜榪欎簺欏剁偣鐨勮礬寰勶紙瀵逛簬<em>V</em>涓墍鏈夐《鐐?em>v</em>闄?em>s</em>澶?em>d[v]</em>= ∞錛夈傚綋綆楁硶緇撴潫鏃訛紝<em>d[v]</em>涓偍瀛樼殑渚挎槸浠?em>s</em>鍒?em>v</em>鐨勬渶鐭礬寰勶紝鎴栬呮槸鏃犵┓澶э紙濡傛灉璺緞涓嶅瓨鍦ㄧ殑璇濓級銆?<br></p> <p>   Dijstra綆楁硶鐨勫熀紜鎿嶄綔鏄竟鐨勬嫇灞曪細(xì)濡傛灉瀛樺湪涓鏉′粠<em>u</em>鍒?em>v</em>鐨勮竟錛岄偅涔堜粠<em>s</em>鍒皏鐨勬渶鐭礬寰勫彲浠ラ氳繃灝嗚竟(<em>u</em>,<em>v</em>)娣誨姞鍒皊鍒皍鐨勫熬閮ㄦ潵鎷撳睍銆傝繖鏉¤礬寰勭殑闀垮害鏄痙[u]+w(u,v)銆傚鏋滆繖涓兼瘮鐩墠宸茬煡鐨?em>d[v]</em>鐨勫艱灝忥紝鎴戜滑鍙互鐢ㄦ柊鍊兼潵鏇夸唬褰撳墠<em>d[v]</em>涓殑鍊箋傛嫇灞曡竟鐨勬搷浣滀竴鐩存墽琛屽埌鎵鏈夌殑d[v]閮戒唬琛ㄤ粠s鍒皏鏈鐭礬寰勭殑鑺辮垂銆傝繖涓畻娉曠粡榪囬傚綋鐨勭粍緇囧洜鑰屽綋<em>d[u]</em>杈懼埌瀹冩渶緇堢殑鍊肩殑鏃跺欙紝姣忔潯杈?<em>u</em>,<em>v</em>)閮藉彧琚嫇灞曚竴嬈°?/p> <p>綆楁硶緇存姢涓や釜欏剁偣闆哠鍜孮銆傞泦鍚圫淇濈暀浜嗘垜浠凡鐭ョ殑鎵鏈塪[v]鐨勫煎凡緇忔槸鏈鐭礬寰勭殑鍊奸《鐐癸紝鑰岄泦鍚圦鍒欎繚鐣欏叾浠栨墍鏈夐《鐐廣傞泦鍚圫鍒濆鐘舵佷負(fù)絀猴紝鑰? 鍚庢瘡涓姝ラ兘鏈変竴涓《鐐逛粠Q縐誨姩鍒癝銆傝繖涓閫夋嫨鐨勯《鐐規(guī)槸Q涓嫢鏈夋渶灝忕殑d[u]鍊肩殑欏剁偣銆傚綋涓涓《鐐箄浠嶲涓漿縐誨埌浜哠涓紝綆楁硶瀵規(guī)瘡鏉″鎺ヨ竟(u,v)榪? 琛屾嫇灞曘?/p> <br> <h3>綆楁硶鎬濇兂</h3> 璁維涓烘渶鐭窛紱誨凡紜畾鐨勯《鐐歸泦錛堢湅浣滅孩鐐歸泦錛夛紝V-S鏄渶鐭窛紱誨皻鏈‘瀹氱殑欏剁偣闆嗭紙鐪嬩綔钃濈偣闆嗭級銆?br> <strong>鈶犲垵濮嬪寲</strong><br>     銆鍒濆鍖栨椂錛屽彧鏈夋簮鐐箂鐨勬渶鐭窛紱繪槸宸茬煡鐨?SD(s)=0)錛屾晠綰㈢偣闆哠={s}錛岃摑鐐歸泦涓虹┖銆?br> <strong>鈶¢噸澶嶄互涓嬪伐浣滐紝鎸夎礬寰勯暱搴﹂掑嬈″簭浜х敓鍚勯《鐐規(guī)渶鐭礬寰?/strong><br>     銆鍦ㄥ綋鍓嶈摑鐐歸泦涓夋嫨涓涓渶鐭窛紱繪渶灝忕殑钃濈偣鏉ユ墿鍏呯孩鐐歸泦錛屼互淇濊瘉鎸夎礬寰勬潈閲嶉掑鐨勬搴忔潵浜х敓鍚勯《鐐圭殑鏈鐭礬寰勩?br>     銆褰撹摑鐐歸泦涓粎鍓╀笅鏈鐭窛紱諱負(fù)∞鐨勮摑鐐癸紝鎴栬呮墍鏈夎摑鐐瑰凡鎵╁厖鍒扮孩鐐歸泦鏃訛紝s鍒版墍鏈夐《鐐圭殑鏈鐭礬寰勫氨姹傚嚭鏉ヤ簡銆?br>   <font color="#ff0000">娉ㄦ剰錛?/font><br>     銆鈶犺嫢浠庢簮鐐瑰埌钃濈偣鐨勮礬寰勪笉瀛樺湪錛屽垯鍙亣璁捐钃濈偣鐨勬渶鐭礬寰勬槸涓鏉¢暱搴︿負(fù)鏃犵┓澶х殑铏氭嫙璺緞銆?br>     銆鈶′粠婧愮偣s鍒扮粓鐐箆鐨勬渶鐭礬寰勭畝縐頒負(fù)v鐨勬渶鐭礬寰勶紱s鍒皏鐨勬渶鐭礬寰勯暱搴︾畝縐頒負(fù)v鐨勬渶鐭窛紱伙紝騫惰涓篠D(v)銆?br><font color="#0000ff"> 錛?錛夊湪钃濈偣闆嗕腑閫夋嫨涓涓渶鐭窛紱繪渶灝忕殑钃濈偣k鏉ユ墿鍏呯孩鐐歸泦</font><br>     銆鏍規(guī)嵁鎸夐暱搴﹂掑搴忎駭鐢熸渶鐭礬寰勭殑鎬濇兂錛屽綋鍓嶆渶鐭窛紱繪渶灝忕殑钃濈偣k鐨勬渶鐭礬寰勬槸錛?br>     銆婧愮偣錛岀孩鐐?錛岀孩鐐?錛?#8230;錛岀孩鐐筺錛岃摑鐐筴<br>  璺濈涓猴細(xì)婧愮偣鍒扮孩鐐筺鏈鐭窛紱?<綰㈢偣n,钃濈偣k>杈歸暱<br>     銆涓烘眰瑙f柟渚匡紝璁劇疆涓涓悜閲廌[0錛庯紟n-1]錛屽浜庢瘡涓摑鐐箆∈ V-S錛岀敤D[v]璁板綍浠庢簮鐐箂鍒拌揪v涓旈櫎v澶栦腑闂翠笉緇忚繃浠諱綍钃濈偣(鑻ユ湁涓棿鐐癸紝鍒欏繀涓虹孩鐐?鐨?鏈鐭?璺緞闀垮害錛堢畝縐頒及璁¤窛紱伙級銆?br>     銆鑻鏄摑鐐歸泦涓及璁¤窛紱繪渶灝忕殑欏剁偣錛屽垯k鐨勪及璁¤窛紱誨氨鏄渶鐭窛紱伙紝鍗寵嫢D[k]=min{D[i] i∈V-S}錛屽垯D[k]=SD(k)銆?br>     銆鍒濆鏃訛紝姣忎釜钃濈偣v鐨凞[c]鍊煎簲涓烘潈w<s錛寁>錛屼笖浠巗鍒皏鐨勮礬寰勪笂娌℃湁涓棿鐐癸紝鍥犱負(fù)璇ヨ礬寰勪粎鍚竴鏉¤竟<s錛寁>銆?br>   <font color="#ff0000">娉ㄦ剰錛?/font><br>     銆鍦ㄨ摑鐐歸泦涓夋嫨涓涓渶鐭窛紱繪渶灝忕殑钃濈偣k鏉ユ墿鍏呯孩鐐歸泦鏄疍ijkstra綆楁硶鐨勫叧閿? <br> <font color="#0000ff"> <br> 錛?錛塳鎵╁厖綰㈢偣闆唖鍚庯紝钃濈偣闆嗕及璁¤窛紱葷殑淇敼</font><br>     銆灝唊鎵╁厖鍒扮孩鐐瑰悗錛屽墿浣欒摑鐐歸泦鐨勪及璁¤窛紱誨彲鑳界敱浜庡鍔犱簡鏂扮孩鐐筴鑰屽噺灝忥紝姝ゆ椂蹇呴』璋冩暣鐩稿簲钃濈偣鐨勪及璁¤窛紱匯?br>     瀵逛簬浠繪剰鐨勮摑鐐筳錛岃嫢k鐢辮摑鍙樼孩鍚庝嬌D[j]鍙樺皬錛屽垯蹇呭畾鏄敱浜庡瓨鍦ㄤ竴鏉′粠s鍒癹涓斿寘鍚柊綰㈢偣k鐨勬洿鐭礬寰勶細(xì)P=<s錛?#8230;錛宬錛宩>銆備笖D [j]鍑忓皬鐨勬柊璺緞P鍙彲鑳芥槸鐢變簬璺緞<s錛?#8230;錛宬>鍜岃竟<k錛宩>緇勬垚銆?br>     銆鎵浠ワ紝褰搇ength(P)=D[k]+w<k錛宩>灝忎簬D[j]鏃訛紝搴旇鐢≒鐨勯暱搴︽潵淇敼D[j]鐨勫箋?br> <br> <font color="#0000ff"> 錛?錛塂ijkstra綆楁硶</font><br> <br>  Dijkstra(G錛孌錛宻){<br>     //鐢―ijkstra綆楁硶姹傛湁鍚戠綉G鐨勬簮鐐箂鍒板悇欏剁偣鐨勬渶鐭礬寰勯暱搴?br>     //浠ヤ笅鏄垵濮嬪寲鎿嶄綔<br>       S={s}錛汥[s]=0錛?//璁劇疆鍒濆鐨勭孩鐐歸泦鍙?qiáng)鏈鐭窛紱?br>       for( all i∈ V-S )do //瀵硅摑鐐歸泦涓瘡涓《鐐筰<br>           D[i]=G[s][i]錛?//璁劇疆i鍒濆鐨勪及璁¤窛紱諱負(fù)w<s錛宨><br>        //浠ヤ笅鏄墿鍏呯孩鐐歸泦<br>       for(i=0;i<n-1;i++)do{//鏈澶氭墿鍏卬-1涓摑鐐瑰埌綰㈢偣闆?br>            D[k]=min{D[i]錛歛ll i V-S}錛?//鍦ㄥ綋鍓嶈摑鐐歸泦涓変及璁¤窛紱繪渶灝忕殑欏剁偣k<br>            if(D[k]絳変簬∞)<br>                 return錛?//钃濈偣闆嗕腑鎵鏈夎摑鐐圭殑浼拌璺濈鍧囦負(fù)∞鏃訛紝<br>                      //琛ㄧず榪欎簺欏剁偣鐨勬渶鐭礬寰勪笉瀛樺湪銆?br>            S=S∪{k}錛?//灝嗚摑鐐筴娑傜孩鍚庢墿鍏呭埌綰㈢偣闆?br>            for( all j∈V-S )do //璋冩暣鍓╀綑钃濈偣鐨勪及璁¤窛紱?br>                if(D[j]>D[k]+G[k][j])<br>                 //鏂扮孩鐐筴浣垮師D[j]鍊煎彉灝忔椂錛岀敤鏂拌礬寰勭殑闀垮害淇敼D[j]錛?br>               //浣縥紱籹鏇磋繎銆?br>                    D[j]=D[k]+G[k][j]錛?br>           }<br>    }<br><br> <p> </p> <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;"></span><span style="color: #000000;"></span></div> <p> </p><img src ="http://www.tkk7.com/cherishchen/aggbug/127882.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/cherishchen/" target="_blank">鍑爮瑙傛搗</a> 2007-07-03 16:28 <a href="http://www.tkk7.com/cherishchen/archive/2007/07/03/127882.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>spring瀛︿範(fàn)鏃ュ織-浜嬪姟綆$悊http://www.tkk7.com/cherishchen/archive/2007/07/03/127860.html鍑爮瑙傛搗鍑爮瑙傛搗Tue, 03 Jul 2007 07:26:00 GMThttp://www.tkk7.com/cherishchen/archive/2007/07/03/127860.htmlhttp://www.tkk7.com/cherishchen/comments/127860.htmlhttp://www.tkk7.com/cherishchen/archive/2007/07/03/127860.html#Feedback0http://www.tkk7.com/cherishchen/comments/commentRss/127860.htmlhttp://www.tkk7.com/cherishchen/services/trackbacks/127860.html鍦╯ervice灞傛帶鍒朵簨鍔?br>

Spring鎺ㄨ崘浜嬪姟鐨勬帶鍒跺湪service灞傚疄鐜幫紝鑰屼笉鏄儚鍗曠嫭浣跨敤hibernate閭f牱錛屽湪dao灞傚疄鐜幫紝榪欐牱鐨勫ソ澶勫湪浜庢洿濂藉湴鏀寔declear鏂瑰紡鐨勪簨鍔★紙service灞傞氬父鎻愪緵鎺ュ彛錛岃繖鏍峰彲浠ラ拡瀵規(guī)帴鍙f潵瀹氫箟浜嬪姟絳栫暐錛岃屼笉鏄拡瀵瑰叿浣撶殑service瀹炵幇錛屽洜姝ゅ彲浠ュ緢鏂逛究鍦版浛鎹ervice鐨勫疄鐜幫紝鑰屼笉闇瑕佷慨鏀逛簨鍔$殑閰嶇疆錛夛紝鏇村姞鐏墊椿銆傚悓鏃訛紝鍙互鏇村姞鏂歸潰鑷劧鍦板疄鐜板叏灞浜嬪姟鐨勬帶鍒躲?/span>

涓句緥濡備笅錛?/p> service鎺ュ彛

package x.y.service;
public interface FooService {
    
    Foo getFoo(String fooName);

    Foo getFoo(String fooName, String barName);

    
void insertFoo(Foo foo);

    
void updateFoo(Foo foo);
}

 


涓涓猻ervice瀹炵幇

package x.y.service;
public class DefaultFooService implements FooService {
    
public Foo getFoo(String fooName) {
        
throw new UnsupportedOperationException();
    }

    
public Foo getFoo(String fooName, String barName) {
        
throw new UnsupportedOperationException();
    }

    
public void insertFoo(Foo foo) {
        
throw new UnsupportedOperationException();
    }

    
public void updateFoo(Foo foo) {
        
throw new UnsupportedOperationException();
    }
}

 

spring.xml錛屾敞鎰忓湪澹版槑浜嬪姟鐨勬椂鍊欙紝鏄拡瀵箂ervice鎺ュ彛鐨勶紝鑰屼笉鏄拡瀵箂ervice瀹炵幇鐨?br>

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop
="http://www.springframework.org/schema/aop"
    xmlns:tx
="http://www.springframework.org/schema/tx"
    xsi:schemaLocation
="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"
>



    
<!-- this is the service object that we want to make transactional -->
    
<bean id="fooService" class="x.y.service.DefaultFooService" />

    
<!-- the transactional advice (i.e. what 'happens'; see the <aop:advisor/> bean below) -->
    
<tx:advice id="txAdvice" transaction-manager="txManager">
        
<!-- the transactional semantics -->
        
<tx:attributes>
            
<!-- all methods starting with 'get' are read-only -->
            
<tx:method name="get*" read-only="true" />

            
<!-- other methods use the default transaction settings (see below) -->
            
<tx:method name="*" />
        
</tx:attributes>
    
</tx:advice>

    
<!-- ensure that the above transactional advice runs for any execution
        of an operation defined by the FooService interface 
-->
    
<aop:config>
        
<aop:pointcut id="fooServiceOperation"
            expression
="execution(* x.y.service.FooService.*(..))" />
        
<aop:advisor advice-ref="txAdvice"
            pointcut-ref
="fooServiceOperation" />
    
</aop:config>

    
<!-- don't forget the DataSource -->
    
<bean id="dataSource"
        class
="org.apache.commons.dbcp.BasicDataSource"
        destroy-method
="close">
        
<property name="driverClassName" value="org.h2.Driver" />
        
<property name="url"
            value
="jdbc:h2:tcp://localhost/D:/try/data/sample;IFEXISTS=TRUE" />
        
<property name="username" value="sa" />
        
<property name="password" value="123456" />
    
</bean>

    
<!-- similarly, don't forget the PlatformTransactionManager -->
    
<bean id="txManager"
        class
="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        
<property name="dataSource" ref="dataSource" />
    
</bean>
    
<!-- other <bean/> definitions here -->
</beans>

 

浣跨敤service灞傛柟渚夸簡浣跨敤鍏ㄥ眬浜嬪姟

瀵逛簬妯法澶氫釜Hibernate SessionFacotry鐨勫垎甯冨紡浜嬪姟錛屽彧闇綆鍗曞湴灝?/span> JtaTransactionManager 鍚屽涓?/span> LocalSessionFactoryBean 鐨勫畾涔夌粨鍚堣搗鏉ヤ綔涓轟簨鍔$瓥鐣ャ備綘鐨勬瘡涓涓?/span>DAO閫氳繃bean灞炴у緱鍒板悇鑷殑 SessionFactory 寮曠敤銆傚湪闇瑕佽繘琛岃法澶氫釜鏁版嵁搴撶殑浜嬪姟鎿嶄綔鏃訛紝鍙渶瑕佸畾涔変竴涓?/span>service灞傦紝浣跨敤 JtaTransactionManager 浣滀負(fù)浜嬪姟絳栫暐錛屾í璺ㄥ涓?/span>DAO鍜屽涓?/span>session factories鏉ュ垝鍒嗕簨鍔★紝鑰屼笉闇瑕佺壒孌婄殑澶勭悊銆?/span>

紺轟緥鐨勯厤緗枃浠跺涓嬶細(xì)

<beans>
  
<bean id="mySessionFactory1" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    
<property name="dataSource" ref="myDataSource1"/>
   ..
  
</bean>
  
<bean id="mySessionFactory2" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    
<property name="dataSource" ref="myDataSource2"/>
 …
  
</bean>
  
<bean id="myTxManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
  
<bean id="myProductDao" class="product.ProductDaoImpl">
    
<property name="sessionFactory" ref="mySessionFactory1"/>
  
</bean>
  
<bean id="myInventoryDao" class="product.InventoryDaoImpl">
    
<property name="sessionFactory" ref="mySessionFactory2"/>
  
</bean>

<aop:config>
    
<aop:pointcut id="productServiceMethods" expression="execution(* product.ProductService.*(..))"/>
    
<aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods"/>
 
</aop:config>

  
<tx:advice id="txAdvice" transaction-manager="myTxManager">
    
<tx:attributes>
      
<tx:method name="increasePrice*" propagation="REQUIRED"/>
      
<tx:method name="someOtherBusinessMethod" propagation="REQUIRES_NEW"/>
      
<tx:method name="*" propagation="SUPPORTS" read-only="true"/>
    
</tx:attributes>
  
</tx:advice>

    
<bean class="product.ProductServiceImpl">
       
<property name="productDao" ref="myProductDao"/>
       
<property name="inventoryDao" ref="myInventoryDao"/>
    
</bean>
    
</beans>






]]>
Jbpm瀛︿範(fàn)loghttp://www.tkk7.com/cherishchen/archive/2007/07/02/127468.html鍑爮瑙傛搗鍑爮瑙傛搗Mon, 02 Jul 2007 03:43:00 GMThttp://www.tkk7.com/cherishchen/archive/2007/07/02/127468.htmlhttp://www.tkk7.com/cherishchen/comments/127468.htmlhttp://www.tkk7.com/cherishchen/archive/2007/07/02/127468.html#Feedback0http://www.tkk7.com/cherishchen/comments/commentRss/127468.htmlhttp://www.tkk7.com/cherishchen/services/trackbacks/127468.htmlIntroduction

    jPDL鏄竴縐嶇洿瑙傜殑嫻佺▼璇█錛岀敤浠ュ睍鐜板晢涓氶昏緫鐨勫鐞嗚繃紼嬨俲PDL鍖呭惈鐨勬蹇墊秹鍙?qiáng)鋼Q鍔°佸紓姝ラ氳鐘舵併佸畾鏃跺櫒銆佽嚜鍔ㄦ墽琛岀殑鍔ㄤ綔絳夛紝涓烘錛屼負(fù)浜嗘暣鍚堜笂榪拌涓猴紝jPDL鎻愪緵浜嗗己澶с佸彲鎵╁睍鐨勬帶鍒舵祦鏈哄埗銆?/p>

graph based execution languages

implementation technique for graph based execution languages錛?/p>

    • based on runtime interpretation of a graph. 
    • based on message queues
    • code generation.

The strategy on how graph execution can be implemented on top of an OO programming language. For those who are familiar with design patterns, it's a combination of the command pattern and the chain of responsibility pattern.

1銆乀ransitions  鍙互鐞嗚В涓鴻繘鍏ュ拰紱誨紑鑺傜偣鐨勭澶達(dá)紝搴旇瀛樺湪澶氫釜Transitions  榪涘叆涓涓妭鐐瑰拰涓涓妭鐐規(guī)湁澶氫釜紱誨紑鐨?strong>Transitions  鐨勬儏鍐?/p>

the structure of the graph is represented with the classes Node and Transition錛岃?tt>Transition鏄叿鏈夋柟鍚戞х殑

image

 

transitions are able to pass the execution from a source node to a destination node with the method take.

transition.take.method

2銆乪xecution 錛岀被浼紁etri涓殑鏍囪錛屾槸鍙樿縼灝辯華鐨勫墠鎻?/strong>

An execution (also known as a token) is represented with a class called Execution. An execution has a reference to the current node.

execution.class

3銆丯ode

A node is a command and has an execute method. Subclasses of Node are supposed to override the execute method to implement some specific behaviour for that node type.

When an execution arrives in a node, that node is executed. The Node's execute method is also responsible for propagating the execution. Propagating the execution means that a node can pass the execution that arrived in the node over one of its leaving transitions to the next node.

When a node's execute method does not propagate the execution, it behaves as a wait state.

Also when a new execution is created, it is initialized in some start node and then waits for an event.

An event is given to an execution and it can trigger the execution to start moving. If the event given to an execution relates to a leaving transition of the current node, the execution takes that transition. The execution then will continue to propagate until it enters another node that behaves as a wait state.

node.execute.method

 

So now we can already see that the two main features are supported : wait states and a graphical representation. During wait states, an Execution just points to a node in the graph

4銆丄ctions

An Action is a command with an execute method. Actions can be associated with events.

Synchronous execution

The default propagation of execution is synchronous.



]]>
JGAP - Genetic Algorithms and Genetic Programminghttp://www.tkk7.com/cherishchen/archive/2007/06/27/126575.html鍑爮瑙傛搗鍑爮瑙傛搗Wed, 27 Jun 2007 05:34:00 GMThttp://www.tkk7.com/cherishchen/archive/2007/06/27/126575.htmlhttp://www.tkk7.com/cherishchen/comments/126575.htmlhttp://www.tkk7.com/cherishchen/archive/2007/06/27/126575.html#Feedback0http://www.tkk7.com/cherishchen/comments/commentRss/126575.htmlhttp://www.tkk7.com/cherishchen/services/trackbacks/126575.htmlhttp://jgap.sourceforge.net/

 

WHAT IS JGAP?

JGAP (pronounced "jay-gap") is a Genetic Algorithms and Genetic Programming component provided as a Java framework. It provides basic genetic mechanisms that can be easily used to apply evolutionary principles to problem solutions. See the examples for a demonstration or watch out the graphical tree that can be created with JGAP for found solutions of genetically evolved programs.
JGAP was designed to be very easy to use "out of the box", while also designed to be highly modular so that more adventurous users can easily plug-in custom genetic operators and other sub-components.

Documentation,  quality and stability of code are the top concerns when developing JGAP. You find really many unit tests packaged with JGAP, extensive Javadocs, and quite a lot of examples. Compare JGAP with other projects! Feedback is always welcome.



]]>
灝忓閥濂界敤鐨凥2鏁版嵁搴?/title><link>http://www.tkk7.com/cherishchen/archive/2007/06/27/126524.html</link><dc:creator>鍑爮瑙傛搗</dc:creator><author>鍑爮瑙傛搗</author><pubDate>Wed, 27 Jun 2007 03:20:00 GMT</pubDate><guid>http://www.tkk7.com/cherishchen/archive/2007/06/27/126524.html</guid><wfw:comment>http://www.tkk7.com/cherishchen/comments/126524.html</wfw:comment><comments>http://www.tkk7.com/cherishchen/archive/2007/06/27/126524.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.tkk7.com/cherishchen/comments/commentRss/126524.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/cherishchen/services/trackbacks/126524.html</trackback:ping><description><![CDATA[<p><a title="http://www.h2database.com/html/frame.html" >http://www.h2database.com/html/frame.html</a></p> <p> </p> <p>鏈榪戜竴涓闈㈢殑紼嬪簭闇瑕佷嬌鐢ㄥ祵鍏ュ紡鏁版嵁搴擄紝閫夋嫨浜嗗緢澶氫笉鍚岀殑宓屽叆寮忔暟鎹?鏈緇堥夋嫨浜咹2錛屾ц兘鏄竴涓緢閲嶈鐨勫師鍥狅紝涓嬪浘鏄痟2鎻愪緵鐨凱erformance鐨勬瘮杈冨浘</p> <p><a title="http://www.h2database.com/html/images/performance.png" >http://www.h2database.com/html/images/performance.png</a></p> <p> </p> <p>h2鏄疶homas Mueller鎻愪緵鐨勪竴涓紑婧愮殑銆佺函java瀹炵幇鐨勫叧緋繪暟鎹簱錛屽湪google涓婇潰鏈夎璁虹粍<a href="mailto:h2-database@googlegroups.com">h2-database@googlegroups.com</a>錛孴homas Mueller涔熼潪甯哥儹鎯咃紝鍥炵瓟闂闈炲父鍙?qiáng)鏃躲?/p> <p> </p> <p>涓嬮潰璇翠笅鎴戞渶緇堥夋嫨h2鐨勫師鍥狅細(xì)</p> <p>錛?錛夋ц兘銆佸皬宸?/p> <p>錛?錛夊悓鏃舵敮鎸佺綉緇滅増鍜屽祵鍏ュ紡鐗堟湰錛屽彟澶栬繕鎻愪緵浜嗗唴瀛樼増</p> <p>錛?錛夋湁姣旇緝濂界殑鍏煎鎬э紝鏀寔鐩稿綋鏍囧噯鐨剆ql鏍囧噯錛堝疄闄呬笂涔熶笉瀛樺湪涓涓暟鎹簱鑳藉100%絎﹀悎鏍囧噯錛?/p> <p>錛?錛夋彁渚涗簡闈炲父鍙嬪ソ鐨勫熀浜巜eb鐨勬暟鎹簱綆$悊鐣岄潰</p> <p>錛?錛夋敮鎸乭ibernate</p> <br> <p><br></p> 琛ュ厖錛?br>鏀寔鐨勪簨鍔¢殧紱葷駭鍒細(xì)<br><br> <h2>Transaction <span id="firstFound" style="color: #000000; background-color: #ffff00;">Isolation</span></h2> <p> This database supports the following transaction <span id="firstFound" style="color: #000000; background-color: #ffff00;">isolation</span> <span style="color: #000000; background-color: #00ffff;">level</span>s: </p> <ul> <li><strong>Serializable</strong><br> This is the default <span style="color: #000000; background-color: #00ffff;">level</span>.<br> To enable, execute the SQL statement 'SET LOCK_MODE 0'<br> or append ;LOCK_MODE=1 to the database URL: jdbc:h2:~/test;LOCK_MODE=1 </li> <li><strong>Read Committed</strong><br> Read locks are released immediately. Higher concurrency is possible when using this <span style="color: #000000; background-color: #00ffff;">level</span>.<br> This is the <span id="firstFound" style="color: #000000; background-color: #ffff00;">isolation</span> <span style="color: #000000; background-color: #00ffff;">level</span> used for many database systems.<br> To enable, execute the SQL statement 'SET LOCK_MODE 0'<br> or append ;LOCK_MODE=3 to the database URL: jdbc:h2:~/test;LOCK_MODE=3 </li> <li><strong>Read Uncommitted</strong><br> This <span style="color: #000000; background-color: #00ffff;">level</span> means that transaction <span id="firstFound" style="color: #000000; background-color: #ffff00;">isolation</span> is disabled.<br> To enable, execute the SQL statement 'SET LOCK_MODE 0'<br> or append ;LOCK_MODE=0 to the database URL: jdbc:h2:~/test;LOCK_MODE=0 </li> </ul> <p> When using the <span id="firstFound" style="color: #000000; background-color: #ffff00;">isolation</span> <span style="color: #000000; background-color: #00ffff;">level</span> 'serializable', dirty reads, non-repeatable reads, and phantom reads are prohibited. </p> <ul> <li><strong>Dirty Reads</strong><br> Means a connection can read uncommitted changes made by another connection.<br> Possible with: read uncommitted </li> <li><strong>Non-Repeatable Reads</strong><br> A connection reads a row, another connection changes a row and commits, and the first connection re-reads the same row and gets the new result.<br> Possible with: read uncommitted, read committed </li> <li><strong>Phantom Reads</strong><br> A connection reads a set of rows using a condition, another connection inserts a row that falls in this condition and commits, then the first connection re-reads using the same condition and gets the new row.<br> Possible with: read uncommitted, read committed </li> </ul> <h3>Table <span style="color: #000000; background-color: #00ffff;">Level</span> Locking</h3> The database allows multiple concurrent connections to the same database. To make sure all connections only see consistent data, table <span style="color: #000000; background-color: #00ffff;">level</span> locking is used. This mechanism does not allow high concurrency, but is very fast. Shared locks and exclusive locks are supported. Before reading from a table, the database tries to add a shared lock to the table (this is only possible if there is no exclusive lock on the object by another connection). If the shared lock is added successfully, the table can be read. It is allowed that other connections also have a shared lock on the same object. If a connection wants to write to a table (update or delete a row), an exclusive lock is required. To get the exclusive lock, other connection must not have any locks on the object. After the connection commits, all locks are released. This database keeps all locks in memory.<br> <img src ="http://www.tkk7.com/cherishchen/aggbug/126524.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/cherishchen/" target="_blank">鍑爮瑙傛搗</a> 2007-06-27 11:20 <a href="http://www.tkk7.com/cherishchen/archive/2007/06/27/126524.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>java寮傚父澶勭悊鐨勪竴鐐規(guī)葷粨錛堝師鍒涳級http://www.tkk7.com/cherishchen/archive/2007/06/25/126132.html鍑爮瑙傛搗鍑爮瑙傛搗Mon, 25 Jun 2007 08:11:00 GMThttp://www.tkk7.com/cherishchen/archive/2007/06/25/126132.htmlhttp://www.tkk7.com/cherishchen/comments/126132.htmlhttp://www.tkk7.com/cherishchen/archive/2007/06/25/126132.html#Feedback0http://www.tkk7.com/cherishchen/comments/commentRss/126132.htmlhttp://www.tkk7.com/cherishchen/services/trackbacks/126132.htmljava鎻愪緵浜嗗緢濂界殑寮傚父澶勭悊鏈哄埗錛屼絾鏄浣曠敤濂藉紓甯稿茍涓嶅鏄擄紝闇瑕佹牴鎹紑鍙戝璞$殑涓嶅悓閲囩敤鐨勫紓甯告満鍒訛紝鏈枃涓昏鍦╡clipse rcp寮鍙戠殑鏃跺欐葷粨鐨勪竴涓紓甯哥殑澶勭悊鏈哄埗錛屼釜浜鴻涓洪傚悎浜庡浘褰㈢晫闈㈠紑鍙戯紝鎬葷粨璧鋒潵錛屽綊綰沖涓嬶細(xì)

錛?錛夊悎鐞嗕嬌鐢╟hecked exception鍜寀nchecked exception錛岃鏄庝嬌鐢ㄨ繖涓ょ寮傚父鐨勫師鍒欑殑鏂囩珷寰堝錛屼笉澶氱綏鍡︿簡

  錛?錛夊紓甯哥殑杞崲錛屽鏋滈渶瑕侊紝鍙互灝嗗簳灞傜殑寮傚父鍖呰涓哄寘鍚洿澶氬惈涔夌殑鑷畾涔夊紓甯擱噸鏂版姏鍑猴紙鍖呮嫭checked鍜?/span>unchecked鐨勮嚜瀹氫箟寮傚父浣撶郴錛夛紝鑷畾涔夊紓甯鎬笉浠呬粎闇瑕佸寘鍚師濮嬬殑寮傚父淇℃伅錛岃繕瑕佸寘鍚竴浜涚壒瀹氱殑鍚箟鍜屽鐞嗘柟娉曪紱

(3) 寮傚父鐨勬姏鍑猴紝灝介噺涓嶈鍦ㄤ腑闂村眰澶勭悊寮傚父錛岃涔堝湪寮傚父鍙戠敓鐨勫湴鏂瑰鐞嗭紝瑕佷箞鎶涘嚭錛屾帹榪熷埌鐢辨渶緇堣皟鐢ㄥ眰鏉ュ鐞嗭紝姣斿鐢?span style="font-size: 10pt;">涓庣敤鎴風(fēng)洿鎺ユ墦浜ら亾鐨?span lang="EN-US">UI灞?/span>錛屾崟鎹夊紓甯革紝騫朵互閿欒淇℃伅妗嗐佸璇濇絳変俊鎭澆浣撳弽棣堣壇濂界殑淇℃伅緇欑敤鎴?/span>

 榪欎篃鍙槸鎴戜釜浜虹殑涓浜涜鐐癸紝甯屾湜澶у鑳界粰鍑烘洿濂界殑鏂瑰紡

鑼冧緥錛?span lang="EN-US">

錛?span lang="EN-US">1錛夊畾涔夎嚜瀹氫箟鐨勫紓甯革細(xì)鍖呮嫭浜嗕袱涓瀯閫犲嚱鏁幫紝涓涓敤浜庢彁渚涢粯璁ょ殑寮傚父淇℃伅錛屼竴涓緵紼嬪簭鍛樻坊鍔犳洿鍔犺緇嗙殑寮傚父淇℃伅錛岃繖涓紓甯革紝鍙互鐢ㄦ潵灝佽鎵鏈夌殑搴曞眰寮傚父錛屼絾鏄竴鑸湪閫昏緫涓婃洿鍔犳竻妤氾紝鍙互澧炲姞涓嶅悓鐨勮嚜瀹氫箟寮傚父錛屾瘮濡傛暟鎹簱澶勭悊寮傚父銆佹枃浠跺鐞嗗紓甯搞佺綉緇滃鐞嗗紓甯哥瓑

public class DataException extends RuntimeException {

    
public DataException(String str, Throwable cause) {

       
super(str, cause);

    }

    
public DataException(Throwable e) {

       
super("鏁版嵁鎿嶄綔鍑洪敊閿欒", e);

    }  

}

 

錛?/span>2錛変嬌鐢ㄨ嚜瀹氫箟鐨勫紓甯稿皝瑁呭簳灞傚紓甯革細(xì)
 

public static boolean exportToExcel(String desLocation,String templateName, List list, String beanName) hrows DataException {

boolean ok = false;

Map beans 
= new HashMap();

beans.put(beanName, list);

XLSTransformer transformer 
= new XLSTransformer();

try {

      transformer.transformXLS(templateName, beans, desLocation);

      ok 
= true;

     } 
catch (ParsePropertyException e) {

       
throw new DataException("瀵煎嚭excel鍑洪敊錛岃В鏋恊xcel鏂囦歡鍑洪敊",e);

     } 
catch (IOException e) {

       
throw new DataException("瀵煎嚭excel鍑洪敊錛屾枃浠舵搷浣滃嚭閿?/span>",e);

    }

return ok;

}

 

錛?span lang="EN-US">3錛夊湪鐢ㄦ埛鐣岄潰閮ㄥ垎鐨勫鐞嗭紝閫氳繃MessageDialog鍙嶉緇欑敤鎴鋒紜殑淇℃伅錛?/span>

try {

String templateName 
= BundlePathUtil.getRealPath(Activator.PLUGIN_ID, "excelTplts\\");

    templateName 
= templateName + "aaa.xls";

    
// 浠巘ableviewer涓幏鍙栨暟鎹?/span>

    List list 
= (List) personTableViewer.getInput();

    ExcelUtil.exportToExcel(desLocation, templateName, list,
"aaa");

catch (DataException e) {

// 榪欓噷鎴戠敤浜唀.getMessage(),浣嗘槸鍐嶆洿瀹為檯鐨勭幆澧冧腑錛屽簲璇ョ粰鏈緇堢敤鎴風(fēng)湅鍒扮殑鏄竴涓弸濂界殑銆侀珮灞傜殑鍑洪敊淇℃伅錛岃緇嗙殑鍑洪敊淇℃伅// 搴旇鍦ㄦ棩蹇楁枃浠朵腑浣撶幇

      MessageDialog.openError(window.getShell(), 
"瀵煎嚭澶辮觸""澶辮觸鍘熷洜錛?/span>"+ e.getMessage());

    
// 閫鍑?/span>

return;

    }

    
// 澧炲姞瀵煎嚭瀹屾垚鐨勬彁紺猴紝姣斿淇℃伅妗?/span>

MessageDialog.openInformation(window.getShell(), 
"瀵煎嚭鎴愬姛""鏌ヨ緇撴灉宸插鍏ュ埌"+ desLocation);

鎬葷粨

  鏍規(guī)嵁java寮傚父浣跨敤鏈浣?jīng)_疄璺碉紝浣跨敤unchecked exception鐨勬晥鐜囨渶楂橈紝灝界unchecked exception涓嶄細(xì)寮鴻揩鐢ㄦ埛鎹曟崏鍜屽鐞嗗紓甯革紝璋冪敤灞傜殑紼嬪簭鍛樹篃鍙互鍑潃涓漢璐d換蹇冩潵榪涜寮傚父鐨勬崟鑾峰拰澶勭悊錛屼絾鏄鏋滀綘涓嶆崟鎹夊鐞嗗紓甯革紝闅忎箣鑰屾潵鐨勬槸紼嬪簭鐨勫仴澹у氨寰椾笉鍒頒繚璇併?/span>

鍙傝冭祫鏂?br>Best Practices for Exception Handling
http://www.onjava.com/pub/a/onjava/2003/11/19/exceptions.html





]]>
浣跨敤h2鐨刢ase鍑芥暟瀹炵幇浜ゅ弶琛?/title><link>http://www.tkk7.com/cherishchen/archive/2007/06/25/126126.html</link><dc:creator>鍑爮瑙傛搗</dc:creator><author>鍑爮瑙傛搗</author><pubDate>Mon, 25 Jun 2007 07:52:00 GMT</pubDate><guid>http://www.tkk7.com/cherishchen/archive/2007/06/25/126126.html</guid><wfw:comment>http://www.tkk7.com/cherishchen/comments/126126.html</wfw:comment><comments>http://www.tkk7.com/cherishchen/archive/2007/06/25/126126.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/cherishchen/comments/commentRss/126126.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/cherishchen/services/trackbacks/126126.html</trackback:ping><description><![CDATA[鏁版嵁琛?span style="font-size: 10pt; font-family: 瀹嬩綋;" lang="EN-US">t鐨刣dl錛?br>create table t(class char(1),callcount int,calldate date)<br></span><img src="http://www.tkk7.com/images/blogjava_net/cherishchen/a1.jpg" border="0"><br><span style="font-size: 10pt; font-family: 瀹嬩綋;" lang="EN-US"><br>sql璇彞:</span> <p class="MsoNormal" style="margin: 6pt 0cm;"><span style="font-size: 10pt; font-family: 瀹嬩綋;" lang="EN-US">select calldate,<o:p></o:p></span></p> <p class="MsoNormal" style="margin: 6pt 0cm;"><span style="font-size: 10pt; font-family: 瀹嬩綋;" lang="EN-US">sum(case class when '1' then callcount else 0 end) as A</span><span style="font-size: 10pt; font-family: 瀹嬩綋;">綾?span lang="EN-US">,<o:p></o:p></span></span></p> <p class="MsoNormal" style="margin: 6pt 0cm;"><span style="font-size: 10pt; font-family: 瀹嬩綋;" lang="EN-US">sum(case class when '2' then callcount else 0 end) as B</span><span style="font-size: 10pt; font-family: 瀹嬩綋;">綾?span lang="EN-US">,<o:p></o:p></span></span></p> <p class="MsoNormal" style="margin: 6pt 0cm;"><span style="font-size: 10pt; font-family: 瀹嬩綋;" lang="EN-US">sum(case class when '3' then callcount else 0 end) as C</span><span style="font-size: 10pt; font-family: 瀹嬩綋;">綾?<span lang="EN-US"><o:p></o:p></span></span></p> <span style="font-size: 10pt; font-family: 瀹嬩綋;" lang="EN-US">from t group by calldate<br><br>鏈鍚庣粨鏋滐細(xì)<br><img src="http://www.tkk7.com/images/blogjava_net/cherishchen/a2.jpg" border="0"><br><br></span><span style="font-size: 10pt; font-family: 瀹嬩綋;" lang="EN-US"><!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <v:stroke joinstyle="miter"/> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0"/> <v:f eqn="sum @0 1 0"/> <v:f eqn="sum 0 0 @1"/> <v:f eqn="prod @2 1 2"/> <v:f eqn="prod @3 21600 pixelWidth"/> <v:f eqn="prod @3 21600 pixelHeight"/> <v:f eqn="sum @0 0 1"/> <v:f eqn="prod @6 1 2"/> <v:f eqn="prod @7 21600 pixelWidth"/> <v:f eqn="sum @8 21600 0"/> <v:f eqn="prod @7 21600 pixelHeight"/> <v:f eqn="sum @10 21600 0"/> </v:formulas> <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/> <o:lock v:ext="edit" aspectratio="t"/> </v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" style="'width:120.75pt; height:96pt'"> <v:imagedata src="file:///C:\DOCUME~1\chen\LOCALS~1\Temp\msohtml1\01\clip_image001.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]--></span><br> <img src ="http://www.tkk7.com/cherishchen/aggbug/126126.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/cherishchen/" target="_blank">鍑爮瑙傛搗</a> 2007-06-25 15:52 <a href="http://www.tkk7.com/cherishchen/archive/2007/06/25/126126.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鍓嶆鏃墮棿鐮旂┒鐨刯pos鐨勬枃妗?/title><link>http://www.tkk7.com/cherishchen/archive/2007/06/25/126116.html</link><dc:creator>鍑爮瑙傛搗</dc:creator><author>鍑爮瑙傛搗</author><pubDate>Mon, 25 Jun 2007 07:18:00 GMT</pubDate><guid>http://www.tkk7.com/cherishchen/archive/2007/06/25/126116.html</guid><wfw:comment>http://www.tkk7.com/cherishchen/comments/126116.html</wfw:comment><comments>http://www.tkk7.com/cherishchen/archive/2007/06/25/126116.html#Feedback</comments><slash:comments>10</slash:comments><wfw:commentRss>http://www.tkk7.com/cherishchen/comments/commentRss/126116.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/cherishchen/services/trackbacks/126116.html</trackback:ping><description><![CDATA[     鎽樿: Jpos浣撶郴緇撴瀯 涓銆?nbsp;  ISOComponet       榪欓噷ISOField鍜孖SOBitMap閮芥槸瀹炵幇浜咺SOComponent鐨勫彾瀛愯妭鐐癸紝ISOMsg鍒欐槸鍖呭惈浜咺SOField鐨凜omposite 錛堢粍鍚堢被錛夛細(xì)ISOMsg綾葷淮鎶や簡Hashtable fields錛岀淮鎶や簡璇ユ姤鏂囩殑鎵鏈夌殑浣嶅厓銆?  鍙傝冿細(xì)composite妯″紡 ...  <a href='http://www.tkk7.com/cherishchen/archive/2007/06/25/126116.html'>闃呰鍏ㄦ枃</a><img src ="http://www.tkk7.com/cherishchen/aggbug/126116.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/cherishchen/" target="_blank">鍑爮瑙傛搗</a> 2007-06-25 15:18 <a href="http://www.tkk7.com/cherishchen/archive/2007/06/25/126116.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://www.tkk7.com/" title="亚洲av成人片在线观看">亚洲av成人片在线观看</a> <div class="friend-links"> </div> </div> </footer> 主站蜘蛛池模板: <a href="http://www50884.com" target="_blank">曰批全过程免费视频网址</a>| <a href="http://yangguang882.com" target="_blank">亚洲色中文字幕无码AV</a>| <a href="http://66keke.com" target="_blank">亚洲人成综合在线播放</a>| <a href="http://yy6636.com" target="_blank">98精品全国免费观看视频</a>| <a href="http://tccqdy.com" target="_blank">亚洲情XO亚洲色XO无码</a>| <a href="http://1444000.com" target="_blank">免费一级做a爰片久久毛片潮</a>| <a href="http://www-777768.com" target="_blank">精品久久久久久久免费加勒比</a>| <a href="http://sdhuamo.com" target="_blank">亚洲精品国产国语</a>| <a href="http://508009.com" target="_blank">91黑丝国产线观看免费</a>| <a href="http://aijiu868.com" target="_blank">亚洲高清不卡视频</a>| <a href="http://gdfcjzx.com" target="_blank">久久aⅴ免费观看</a>| <a href="http://959901cc.com" target="_blank">亚洲成A人片在线观看无码不卡</a>| <a href="http://cnpc1002.com" target="_blank">eeuss影院免费直达入口</a>| <a href="http://jxszzhzs.com" target="_blank">亚洲精品动漫人成3d在线</a>| <a href="http://72c5.com" target="_blank">男人和女人高潮免费网站</a>| <a href="http://qqcao7.com" target="_blank">免费人成在线观看播放国产</a>| <a href="http://8xk7u9.com" target="_blank">欧洲亚洲国产精华液</a>| <a href="http://sjmthanks.com" target="_blank">高清国语自产拍免费视频国产 </a>| <a href="http://350725.com" target="_blank">95免费观看体验区视频</a>| <a href="http://565636.com" target="_blank">亚洲爆乳无码一区二区三区</a>| <a href="http://youkabaitiao.com" target="_blank">三级黄色片免费看</a>| <a href="http://52ku6.com" target="_blank">亚洲乱码中文字幕久久孕妇黑人</a>| <a href="http://91sebo.com" target="_blank">国产三级在线免费观看</a>| <a href="http://kencery.com" target="_blank">中文字幕在亚洲第一在线</a>| <a href="http://97chaopeng2.com" target="_blank">国产精品极品美女自在线观看免费</a>| <a href="http://hysw100.com" target="_blank">亚洲色偷偷狠狠综合网</a>| <a href="http://hqwgg.com" target="_blank">国产精品综合专区中文字幕免费播放</a>| <a href="http://565636.com" target="_blank">亚洲国产日韩成人综合天堂</a>| <a href="http://155lh.com" target="_blank">一个人免费观看视频在线中文</a>| <a href="http://eoeoyui.com" target="_blank">爱情岛论坛网亚洲品质自拍</a>| <a href="http://0515bh.com" target="_blank">和老外3p爽粗大免费视频</a>| <a href="http://da666f.com" target="_blank">亚洲精品无码鲁网中文电影</a>| <a href="http://kdp44.com" target="_blank">精品国产免费一区二区三区香蕉</a>| <a href="http://smalody.com" target="_blank">亚洲av最新在线网址</a>| <a href="http://yulongfilm.com" target="_blank">色欲A∨无码蜜臀AV免费播 </a>| <a href="http://gyjinzheng.com" target="_blank">成人A毛片免费观看网站</a>| <a href="http://77tok.com" target="_blank">久久精品国产精品亚洲</a>| <a href="http://amgzh.com" target="_blank">伊人久久大香线蕉免费视频</a>| <a href="http://chaikexin.com" target="_blank">国产亚洲AV无码AV男人的天堂</a>| <a href="http://js06vip.com" target="_blank">久久青青草原国产精品免费</a>| <a href="http://sese3366.com" target="_blank">亚洲影院在线观看</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>