﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-每日E读-随笔分类-JAVA</title><link>http://www.blogjava.net/hexuzhong/category/1133.html</link><description>HexUzHoNG</description><language>zh-cn</language><lastBuildDate>Tue, 27 Feb 2007 12:24:29 GMT</lastBuildDate><pubDate>Tue, 27 Feb 2007 12:24:29 GMT</pubDate><ttl>60</ttl><item><title>Recipe 4.10 Program: Apache Logfile Parsing</title><link>http://www.blogjava.net/hexuzhong/archive/2006/02/07/29858.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Tue, 07 Feb 2006 13:14:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2006/02/07/29858.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/29858.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2006/02/07/29858.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/29858.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/29858.html</trackback:ping><description><![CDATA[<P>Recipe4.10 apache log分析程序</P>
<P>通过前面的几节，现在看一个实例：apache的日志分析程序。以我本机的apache log为例，如下：<BR>192.168.1.138 - - [03/Feb/2006:01:40:20 +0800] "GET /phpinfo.php HTTP/1.1" 404 295<BR>//分别为 客户端IP、访问日期、请求路径、服务端响应Code、请求文件大小</P>
<P>其正则表达式为：<BR>^([\d.]+) (\S+) (\S+) \[([\w:/]+\s[+\-]\d{4})\] "(.+?)" (\d{3}) (\d+)</P>
<P>想到前面正则中()的作用了么？可以通过group(i)快速的将每组()中类容提取出来。<BR>第一组([\d.]+)：将IP地址匹配出来<BR>第四组([\w:/]+\s[+\-]\d{4})：将时间匹配出来<BR>第五组"(.+?)"：将客户端请求内容匹配出来<BR>第六组(\d{3})：将服务端响应Code匹配出来<BR>第七组(\d+)：将文件大小匹配出来</P>
<P>关于那些正则表达式元字符的语法详见：<BR><A href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html">http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html</A><BR><BR>测试程序：<BR></P>
<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG id=Codehighlighter1_40_755_Open_Image onclick="this.style.display='none'; Codehighlighter1_40_755_Open_Text.style.display='none'; Codehighlighter1_40_755_Closed_Image.style.display='inline'; Codehighlighter1_40_755_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_40_755_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_40_755_Closed_Text.style.display='none'; Codehighlighter1_40_755_Open_Image.style.display='inline'; Codehighlighter1_40_755_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;main(String[]&nbsp;args)&nbsp;</SPAN><SPAN id=Codehighlighter1_40_755_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_40_755_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;pattern&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">^([\\d.]+)&nbsp;(\\S+)&nbsp;(\\S+)&nbsp;\\[([\\w:/]+\\s[+\\-]\\d{4})\\]&nbsp;\</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">&nbsp;(\\d{3})&nbsp;(\\d+)</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;log&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">192.168.1.138&nbsp;-&nbsp;-&nbsp;[03/Feb/2006:01:40:20&nbsp;+0800]&nbsp;\</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">GET&nbsp;</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">phpinfo.php&nbsp;HTTP</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">1.1</SPAN><SPAN style="COLOR: #000000">\</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;404&nbsp;295</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">pattern:&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;pattern);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">log:&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;log);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Pattern&nbsp;p&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;Pattern.compile(pattern);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Matcher&nbsp;m&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;p.matcher(log);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG id=Codehighlighter1_456_708_Open_Image onclick="this.style.display='none'; Codehighlighter1_456_708_Open_Text.style.display='none'; Codehighlighter1_456_708_Closed_Image.style.display='inline'; Codehighlighter1_456_708_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_456_708_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_456_708_Closed_Text.style.display='none'; Codehighlighter1_456_708_Open_Image.style.display='inline'; Codehighlighter1_456_708_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(m.find())&nbsp;</SPAN><SPAN id=Codehighlighter1_456_708_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_456_708_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">IP&nbsp;Address:&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;m.group(</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Date&amp;Time:&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;m.group(</SPAN><SPAN style="COLOR: #000000">4</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Request:&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;m.group(</SPAN><SPAN style="COLOR: #000000">5</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Response:&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;m.group(</SPAN><SPAN style="COLOR: #000000">6</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Size:&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;m.group(</SPAN><SPAN style="COLOR: #000000">7</SPAN><SPAN style="COLOR: #000000">));<BR><IMG id=Codehighlighter1_715_752_Open_Image onclick="this.style.display='none'; Codehighlighter1_715_752_Open_Text.style.display='none'; Codehighlighter1_715_752_Closed_Image.style.display='inline'; Codehighlighter1_715_752_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_715_752_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_715_752_Closed_Text.style.display='none'; Codehighlighter1_715_752_Open_Image.style.display='inline'; Codehighlighter1_715_752_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN id=Codehighlighter1_715_752_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_715_752_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">error!</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG id=Codehighlighter1_759_1080_Open_Image onclick="this.style.display='none'; Codehighlighter1_759_1080_Open_Text.style.display='none'; Codehighlighter1_759_1080_Closed_Image.style.display='inline'; Codehighlighter1_759_1080_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_759_1080_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_759_1080_Closed_Text.style.display='none'; Codehighlighter1_759_1080_Open_Image.style.display='inline'; Codehighlighter1_759_1080_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_759_1080_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</SPAN><SPAN id=Codehighlighter1_759_1080_Open_Text><SPAN style="COLOR: #008000">/*</SPAN><SPAN style="COLOR: #008000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;程序输出:<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;pattern:&nbsp;^([\d.]+)&nbsp;(\S+)&nbsp;(\S+)&nbsp;\[([\w:/]+\s[+\-]\d{4})\]&nbsp;"(.+?)"&nbsp;(\d{3})&nbsp;(\d+)<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;log:&nbsp;192.168.1.138&nbsp;-&nbsp;-&nbsp;[03/Feb/2006:01:40:20&nbsp;+0800]&nbsp;"GET&nbsp;/phpinfo.php&nbsp;HTTP/1.1"&nbsp;404&nbsp;295<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;IP&nbsp;Address:&nbsp;192.168.1.138<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Date&amp;Time:&nbsp;03/Feb/2006:01:40:20&nbsp;+0800<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Request:&nbsp;GET&nbsp;/phpinfo.php&nbsp;HTTP/1.1<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Response:&nbsp;404<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Size:&nbsp;295<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">*/</SPAN></SPAN></DIV><img src ="http://www.blogjava.net/hexuzhong/aggbug/29858.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2006-02-07 21:14 <a href="http://www.blogjava.net/hexuzhong/archive/2006/02/07/29858.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java Cookbook -&gt; Recipe 4.4 Replacing the Matched Text </title><link>http://www.blogjava.net/hexuzhong/archive/2006/02/05/29593.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Sun, 05 Feb 2006 06:24:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2006/02/05/29593.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/29593.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2006/02/05/29593.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/29593.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/29593.html</trackback:ping><description><![CDATA[<P>Recipe 4.4 替换匹配的字符串</P>
<P>在4.3中介绍了查找到匹配正则表达式的功能，假如需要替换掉匹配正则表达式的字符串，我们可以自已使用String类的subString()方法，但jdk1.4的正则表达式API中提供了实现此功能的相关方法，如下：</P>
<P><FONT color=#ff0000>*</FONT> replaceAll(newString); 替换全部符合正则表达式的子串为newString.</P>
<P><FONT color=#ff0000>*</FONT> appendReplacement(StringBuffer, newString); 将字符串中匹配正则的子串之前的字符串先传入到StringBuffer中，然后再加上newString。</P>
<P><FONT color=#ff0000>*</FONT> appendTail(StringBuffer); 将字符串中匹配最后一个正则表达式后面的字符串传入到StringBuffer(通常和appendReplacement一起使用).</P>
<P>appendReplacement()和appendTail()看原文没太理解，上面的描述是通过debug看StringBuffer中的变化得来的。：）</P>
<P>看下面的例子：<BR></P>
<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;匹配d开头,接着是a或e最少一次，最多2次，再接着是mon<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;感觉自已跟唐僧一样，N啰嗦&nbsp;-__-!!</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;pattern&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">d[ae]{1,2}mon</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;input&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Unix&nbsp;hath&nbsp;demons&nbsp;and&nbsp;deamons&nbsp;in&nbsp;it!</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Input:&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;input);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Pattern&nbsp;p&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;Pattern.compile(pattern);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Matcher&nbsp;m&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;p.matcher(input);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;两个子串符合:&nbsp;demons,&nbsp;deamons.</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">ReplaceAll:&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;m.replaceAll(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">deamon</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m.reset();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StringBuffer&nbsp;sb&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;StringBuffer();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Append&nbsp;methods:&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;这个地方用debug跟着走一圈<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;第一次StringBuffer中为:&nbsp;Unix&nbsp;hath&nbsp;deamons<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;第二次StringBuffer为:&nbsp;Unix&nbsp;hath&nbsp;deamons&nbsp;and&nbsp;deamons</SPAN><SPAN style="COLOR: #008000"><BR><IMG id=Codehighlighter1_686_743_Open_Image onclick="this.style.display='none'; Codehighlighter1_686_743_Open_Text.style.display='none'; Codehighlighter1_686_743_Closed_Image.style.display='inline'; Codehighlighter1_686_743_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_686_743_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_686_743_Closed_Text.style.display='none'; Codehighlighter1_686_743_Open_Image.style.display='inline'; Codehighlighter1_686_743_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">while</SPAN><SPAN style="COLOR: #000000">&nbsp;(m.find())&nbsp;</SPAN><SPAN id=Codehighlighter1_686_743_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_686_743_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m.appendReplacement(sb,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">deamon</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;执行完appendTail()中后为:&nbsp;Unix&nbsp;hath&nbsp;deamons&nbsp;and&nbsp;deamons&nbsp;in&nbsp;it!</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m.appendTail(sb);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(sb.toString());</SPAN></DIV><img src ="http://www.blogjava.net/hexuzhong/aggbug/29593.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2006-02-05 14:24 <a href="http://www.blogjava.net/hexuzhong/archive/2006/02/05/29593.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java Cookbook -&gt; Recipe 4.3 Finding the Matching Text </title><link>http://www.blogjava.net/hexuzhong/archive/2006/02/03/29479.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Thu, 02 Feb 2006 16:07:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2006/02/03/29479.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/29479.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2006/02/03/29479.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/29479.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/29479.html</trackback:ping><description><![CDATA[<P>Finding the Matching Text<BR><BR>有时候你需要把字符串中匹配正则表达式的那一段找出来，接着前一个例子（4.2）你可以调用“查找”方法成功后，调用下面的方法将匹配的字符串找出来。：）</P>
<P>start(), end()&nbsp; 返回字符串中匹配正则表达式的子串的开始位置和结束位置</P>
<P>groupCount()&nbsp; 返回()号匹配的数目，如果有的话。返回0表示没有使用()组，下面将会有介绍</P>
<P>group(int i)&nbsp; 返回正则表达式()匹配的第i组，如果i小于或等于groupCount()则返回相应的()匹配值，如果调用group(0)或group()则返回整个匹配正则表达式的部分</P>
<P>下面这个例子使用group()直接将整个匹配正则表达式的子字符串取出来：</P>
<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG id=Codehighlighter1_40_426_Open_Image onclick="this.style.display='none'; Codehighlighter1_40_426_Open_Text.style.display='none'; Codehighlighter1_40_426_Closed_Image.style.display='inline'; Codehighlighter1_40_426_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_40_426_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_40_426_Closed_Text.style.display='none'; Codehighlighter1_40_426_Open_Image.style.display='inline'; Codehighlighter1_40_426_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;main(String[]&nbsp;args)&nbsp;</SPAN><SPAN id=Codehighlighter1_40_426_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_40_426_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;匹配Q开头，第二个字符不为u，后面接数字1次或多次，后面再.号</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;pattern&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Q[^u]\\d+\\.</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Pattern&nbsp;p&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;Pattern.compile(pattern);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;line&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Order&nbsp;QT300.&nbsp;Now&nbsp;!</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Matcher&nbsp;m&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;p.matcher(line);<BR><IMG id=Codehighlighter1_245_377_Open_Image onclick="this.style.display='none'; Codehighlighter1_245_377_Open_Text.style.display='none'; Codehighlighter1_245_377_Closed_Image.style.display='inline'; Codehighlighter1_245_377_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_245_377_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_245_377_Closed_Text.style.display='none'; Codehighlighter1_245_377_Open_Image.style.display='inline'; Codehighlighter1_245_377_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(m.find())&nbsp;</SPAN><SPAN id=Codehighlighter1_245_377_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_245_377_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;m.group()须调用相关查找方法成功后才能调用</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(pattern&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;matches&nbsp;\</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">&nbsp;+&nbsp;m.group()&nbsp;+&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">\</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;in&nbsp;\</SPAN><SPAN style="COLOR: #000000">""<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;line&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</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><IMG id=Codehighlighter1_384_423_Open_Image onclick="this.style.display='none'; Codehighlighter1_384_423_Open_Text.style.display='none'; Codehighlighter1_384_423_Closed_Image.style.display='inline'; Codehighlighter1_384_423_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_384_423_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_384_423_Closed_Text.style.display='none'; Codehighlighter1_384_423_Open_Image.style.display='inline'; Codehighlighter1_384_423_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN id=Codehighlighter1_384_423_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_384_423_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">NO&nbsp;MATCH</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;输出：Q[^u]\d+\.&nbsp;matches&nbsp;"QT300."&nbsp;in&nbsp;"Order&nbsp;QT300.&nbsp;Now&nbsp;!"</SPAN></DIV><BR>上面这个例子也可以使用start(), end()方法来完成：<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG id=Codehighlighter1_40_387_Open_Image onclick="this.style.display='none'; Codehighlighter1_40_387_Open_Text.style.display='none'; Codehighlighter1_40_387_Closed_Image.style.display='inline'; Codehighlighter1_40_387_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_40_387_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_40_387_Closed_Text.style.display='none'; Codehighlighter1_40_387_Open_Image.style.display='inline'; Codehighlighter1_40_387_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;main(String[]&nbsp;args)&nbsp;</SPAN><SPAN id=Codehighlighter1_40_387_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_40_387_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;pattern&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Q[^u]\\d+\\.</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Pattern&nbsp;p&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;Pattern.compile(pattern);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;line&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Order&nbsp;QT300.&nbsp;Now!</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Matcher&nbsp;m&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;p.matcher(line);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_207_337_Open_Image onclick="this.style.display='none'; Codehighlighter1_207_337_Open_Text.style.display='none'; Codehighlighter1_207_337_Closed_Image.style.display='inline'; Codehighlighter1_207_337_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_207_337_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_207_337_Closed_Text.style.display='none'; Codehighlighter1_207_337_Open_Image.style.display='inline'; Codehighlighter1_207_337_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(m.find())&nbsp;</SPAN><SPAN id=Codehighlighter1_207_337_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_207_337_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(pattern&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;matches&nbsp;\</SPAN><SPAN style="COLOR: #000000">""<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;line.substring(m.start(),&nbsp;m.end())&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">\</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;in&nbsp;\</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;line<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</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><IMG id=Codehighlighter1_344_384_Open_Image onclick="this.style.display='none'; Codehighlighter1_344_384_Open_Text.style.display='none'; Codehighlighter1_344_384_Closed_Image.style.display='inline'; Codehighlighter1_344_384_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_344_384_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_344_384_Closed_Text.style.display='none'; Codehighlighter1_344_384_Open_Image.style.display='inline'; Codehighlighter1_344_384_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN id=Codehighlighter1_344_384_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_344_384_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">NO&nbsp;MATCH!</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN></DIV><BR>假设你想将字符串:<BR>Smith, John<BR>通过正则转换为：<BR>John Smith<BR>可以这样做：<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG id=Codehighlighter1_40_445_Open_Image onclick="this.style.display='none'; Codehighlighter1_40_445_Open_Text.style.display='none'; Codehighlighter1_40_445_Closed_Image.style.display='inline'; Codehighlighter1_40_445_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_40_445_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_40_445_Closed_Text.style.display='none'; Codehighlighter1_40_445_Open_Image.style.display='inline'; Codehighlighter1_40_445_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;main(String[]&nbsp;args)&nbsp;</SPAN><SPAN id=Codehighlighter1_40_445_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_40_445_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;line&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Smith,&nbsp;John</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;这就是上面所说的()号,如果调用groupCount()的话,将输出2<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;匹配任何字符0次或多次,然后是","号和空格,再匹配任何字符0次和多次<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;上面的任何字符不包括换行符</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Pattern&nbsp;p&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;Pattern.compile(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">(.*),&nbsp;(.*)</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Matcher&nbsp;m&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;p.matcher(line);<BR><IMG id=Codehighlighter1_270_395_Open_Image onclick="this.style.display='none'; Codehighlighter1_270_395_Open_Text.style.display='none'; Codehighlighter1_270_395_Closed_Image.style.display='inline'; Codehighlighter1_270_395_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_270_395_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_270_395_Closed_Text.style.display='none'; Codehighlighter1_270_395_Open_Image.style.display='inline'; Codehighlighter1_270_395_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(m.find())&nbsp;</SPAN><SPAN id=Codehighlighter1_270_395_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_270_395_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;先取上面正则()中匹配的group&nbsp;2,也就是John<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;然后再取()中匹配的group&nbsp;1,也就是Smith</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(m.group(</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;m.group(</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">));<BR><IMG id=Codehighlighter1_402_442_Open_Image onclick="this.style.display='none'; Codehighlighter1_402_442_Open_Text.style.display='none'; Codehighlighter1_402_442_Closed_Image.style.display='inline'; Codehighlighter1_402_442_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_402_442_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_402_442_Closed_Text.style.display='none'; Codehighlighter1_402_442_Open_Image.style.display='inline'; Codehighlighter1_402_442_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN id=Codehighlighter1_402_442_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_402_442_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">NO&nbsp;MATCH!</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;输出:&nbsp;John&nbsp;Smith</SPAN></DIV><img src ="http://www.blogjava.net/hexuzhong/aggbug/29479.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2006-02-03 00:07 <a href="http://www.blogjava.net/hexuzhong/archive/2006/02/03/29479.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java Cookbook -&gt; Recipe 4.2 Using regexes in Java: Test for a Pattern</title><link>http://www.blogjava.net/hexuzhong/archive/2006/02/02/29467.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Thu, 02 Feb 2006 05:02:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2006/02/02/29467.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/29467.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2006/02/02/29467.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/29467.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/29467.html</trackback:ping><description><![CDATA[在JDK1.4中添加了java.util.regex这个包，用来处理正则表达式。<BR>在java中我们可以简单的使用String类的　matches() 方法来判断当前字符串是否符合你所给定的正则表达式模式。matches()方法接受正则表达式做为参数，返回boolean类型。<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG id=Codehighlighter1_39_78_Open_Image onclick="this.style.display='none'; Codehighlighter1_39_78_Open_Text.style.display='none'; Codehighlighter1_39_78_Closed_Image.style.display='inline'; Codehighlighter1_39_78_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_39_78_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_39_78_Closed_Text.style.display='none'; Codehighlighter1_39_78_Open_Image.style.display='inline'; Codehighlighter1_39_78_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(inputString.matches(regexPattern))&nbsp;</SPAN><SPAN id=Codehighlighter1_39_78_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_39_78_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;字符串inputString匹配regexPattern这个模式</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top></SPAN><SPAN style="COLOR: #000000">}</SPAN></SPAN></DIV>代码很简单，但是效率不高，如果在程序中使用不止一次，我们可以使用Pattern和Matcher，例子见下：<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG id=Codehighlighter1_70_372_Open_Image onclick="this.style.display='none'; Codehighlighter1_70_372_Open_Text.style.display='none'; Codehighlighter1_70_372_Closed_Image.style.display='inline'; Codehighlighter1_70_372_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_70_372_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_70_372_Closed_Text.style.display='none'; Codehighlighter1_70_372_Open_Image.style.display='inline'; Codehighlighter1_70_372_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;main(String[]&nbsp;args)&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throws</SPAN><SPAN style="COLOR: #000000">&nbsp;PatternSyntaxException&nbsp;</SPAN><SPAN id=Codehighlighter1_70_372_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_70_372_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;pattern&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">^Q[^u]\\d+\\.</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;input&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Qa777.&nbsp;is&nbsp;the&nbsp;next&nbsp;flight.&nbsp;It&nbsp;is&nbsp;on&nbsp;time.</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Pattern&nbsp;p&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;Pattern.compile(pattern);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">boolean</SPAN><SPAN style="COLOR: #000000">&nbsp;found&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;p.matcher(input).lookingAt();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;pattern&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;(found&nbsp;</SPAN><SPAN style="COLOR: #000000">?</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;matches&nbsp;'</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;:&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;doesn't&nbsp;match&nbsp;'</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;input&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN></DIV>
<P>在程序中使用正则表达式的步骤一般如下：<BR>1. 建立Pattern对象，通过静态方法Pattern.compile();<BR>2. 取得Matcher对象，通过pattern.matcher(CharSequence charSequence);<BR>3. 调用Matcher对象的相关查找方法。</P>
<P>java.lang.CharSequence接口是在JDK1.4版本中被添加进来的，它为不同种类的char序列提供了统一的只读访问。实现的类有String, StringBuffer, java.nio.CharBuffer</P>
<P>Matcher提供几个有不同的查找方法，比String类的matches()方法更灵活，如下：</P>
<P>match() 使用整个字符串与相关模式相比较，和String的matches()差不多</P>
<P>lookingAt() 从字符串开头的地方与相关模式比较</P>
<P>find() 匹配字符串，没有必要从字符串的第一个字符开始，如果前一个操作匹配，而且匹配器没有重置的话，则从不匹配的第一个字符开始。</P>
<P>上面每个方法都返回boolean类型，返回true则意味的匹配，返回false则不匹配。</P>
<P>要检测给定的String是否匹配给定的模式，只须下面这样就可以了：<BR></P>
<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">Matcher&nbsp;m&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;Pattern.compile(yourPattern).matcher(yourString);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG id=Codehighlighter1_77_109_Open_Image onclick="this.style.display='none'; Codehighlighter1_77_109_Open_Text.style.display='none'; Codehighlighter1_77_109_Closed_Image.style.display='inline'; Codehighlighter1_77_109_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_77_109_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_77_109_Closed_Text.style.display='none'; Codehighlighter1_77_109_Open_Image.style.display='inline'; Codehighlighter1_77_109_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(m.find())&nbsp;</SPAN><SPAN id=Codehighlighter1_77_109_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_77_109_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">match</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG id=Codehighlighter1_116_151_Open_Image onclick="this.style.display='none'; Codehighlighter1_116_151_Open_Text.style.display='none'; Codehighlighter1_116_151_Closed_Image.style.display='inline'; Codehighlighter1_116_151_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_116_151_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_116_151_Closed_Text.style.display='none'; Codehighlighter1_116_151_Open_Image.style.display='inline'; Codehighlighter1_116_151_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN id=Codehighlighter1_116_151_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_116_151_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">no&nbsp;match</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV><img src ="http://www.blogjava.net/hexuzhong/aggbug/29467.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2006-02-02 13:02 <a href="http://www.blogjava.net/hexuzhong/archive/2006/02/02/29467.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>利用P6SPY ＋SQL Profiler记录、统计web app对数据库的操作。</title><link>http://www.blogjava.net/hexuzhong/archive/2006/01/28/29345.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Sat, 28 Jan 2006 15:05:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2006/01/28/29345.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/29345.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2006/01/28/29345.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/29345.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/29345.html</trackback:ping><description><![CDATA[<P>弄hibernate时，想显示sql语句，可以设置show_sql为true来达到这个目的，但是参数值全是像PreparedStatement一样，用?来代替的。<BR>用p6spy可以达到显示的那些参数原值的目的，但可读性差。可以利用SQL Profiler来处理这个事情。<BR>p6spy: <A href="http://www.p6spy.com/">http://www.p6spy.com</A><BR>SQL Profile: <A href="http://www.jahia.net/jahia/page597.html">http://www.jahia.net/jahia/page597.html</A><BR><BR>p6spy安装：<BR><FONT color=#ff0000>*</FONT> 将p6spy.jar放到WEB-INF/lib目录下，将spy.properties放到WEB-INF/classes目录下。<BR><FONT color=#ff0000>*</FONT> 修改你 原有 JDBC Driver为：com.p6spy.engine.spy.P6SpyDriver<BR><FONT color=#ff0000>*</FONT> 修改 spy.properties 中的 realdriver 值为 原有 的JDBC Driver，比如我的是：com.mysql.jdbc.Driver<BR><FONT color=#ff0000>*</FONT> 完成，运行web server。<BR><BR>我的日志记录产生在 %TOMCAT_HOME%\bin下，此log位置可以能过修改 logfile&nbsp;&nbsp;= x:\x_dir\spy.log 来控制<BR>打开看看，看里面的日志是不是看起来比较不爽？下面我们安装SQL Profiler来让自已的视线爽一点。<BR><BR>SQL Profiler安装：（须p6spy成功安装）<BR><FONT color=#ff0000>*</FONT> 将SQL Profiler自带的spy.properties覆盖原来的classes目录下文件<BR><FONT color=#ff0000>*</FONT> 修改现在spy.properties中realdriver 值为 原有 的JDBC Driver<BR>看后看看readme注意这几句 ^__^ ：<BR>1. Start the GUI<BR>2. Start the webapp, in starts doing some JDBC requests we will ignore<BR>3. Press the "reset" button on the GUI<BR>4. Make a request to the webapp<BR>5. Press the "pause" button after the request has finished executing<BR>6. Press the "report" button to save profiling results as a CSV file<BR><BR><FONT color=#ff0000>*</FONT> 我们先用java -jar sqlprofiler.jar 运行 sql profiler<BR><FONT color=#ff0000>*</FONT> 然后启动web server :-)<BR><BR>一切尽在眼前了吧？ <BR>当然，p6spy 和 sql profiler 能做的不止这些，sql profiler还能根据你的query来帮你生成建立合适的index功能等等。<BR><BR><FONT color=#000000>PS:&nbsp;祝大家新年快乐，万事如意。</FONT>&nbsp;&nbsp;<BR></P><img src ="http://www.blogjava.net/hexuzhong/aggbug/29345.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2006-01-28 23:05 <a href="http://www.blogjava.net/hexuzhong/archive/2006/01/28/29345.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>免费的Subversion服务器申请，及时开通。</title><link>http://www.blogjava.net/hexuzhong/archive/2006/01/01/26242.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Sun, 01 Jan 2006 02:10:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2006/01/01/26242.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/26242.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2006/01/01/26242.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/26242.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/26242.html</trackback:ping><description><![CDATA[<P>Quote:<BR>
<HR>
Subversion是一个优秀的版本控制工具，因为关于版本许多人把这个单词想当然的理解为“子版本”，实际上subversion本身是一个单词，并不是合成词，它的意思是颠覆。<BR><BR>这本身就是个很酷的单词，而我们也要颠覆许多我们习以为常的事情，用Subversion改变我们的工作和生活。<BR>
<HR>
<BR><A href="http://www.javaforge.com">http://www.javaforge.com</A>&nbsp;提供免费的Subversion服务器申请，对于公司来说也许没什么很大的用处，但对网上朋友小型的团队开发，而又没有自已的版本控制服务器的朋友来说还是挺有用的。<BR><BR>昨天申请了个试了试：注册帐号，建立项目，就可以即时开通这项服务了，无需提交给管理员验证。爽！<BR>申请后，可以通过svn客户端（如eclipse的subclipse）访问 <A href="http://svn.javaforge.com:80/svn/">http://svn.javaforge.com:80/svn/</A>项目名 来进行管理了。<BR></P><img src ="http://www.blogjava.net/hexuzhong/aggbug/26242.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2006-01-01 10:10 <a href="http://www.blogjava.net/hexuzhong/archive/2006/01/01/26242.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Struts Validator验证日期类型出错+解决  :-)</title><link>http://www.blogjava.net/hexuzhong/archive/2005/12/18/24483.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Sun, 18 Dec 2005 06:19:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2005/12/18/24483.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/24483.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2005/12/18/24483.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/24483.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/24483.html</trackback:ping><description><![CDATA[最开始是使用datePattern模式<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">var</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">var-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">datePatternStrict</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">var-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">var-value</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">yyyy/MM/dd</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">var-value</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">var</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV>输入正确数据能通过验证,但故意输入错误日期,它没有提示你日期输入有误,而是在console上输出错误信息:<BR>10:10:17,359&nbsp; WARN GenericTypeValidator: abcd<BR>java.text.ParseException: Unparseable date: "abcd"<BR>&nbsp;at java.text.DateFormat.parse(DateFormat.java:335)<BR>&nbsp;at org.apache.commons.validator.GenericTypeValidator.formatDate(GenericTypeValidator.java:213)<BR>&nbsp;at org.apache.struts.validator.FieldChecks.validateDate(FieldChecks.java:540)<BR>&nbsp;at org.apache.struts.util.StrutsValidator.validateDate(StrutsValidator.java:309)<BR>&nbsp;at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<BR>&nbsp;at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<BR>&nbsp;at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<BR>&nbsp;at java.lang.reflect.Method.invoke(Method.java:585)<BR><BR>找了好久,最后看到struts中自带的例子使用datePatternStrict模式<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">var</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">var-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">datePatternStrict</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">var-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">var-value</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">yyyy/MM/dd</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">var-value</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">var</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV>试了下,OK,成功.....<BR><BR>但为啥datePattern不行呢....... <IMG height=20 src="http://www.blogjava.net/Emoticons/hitwall.gif" width=25 border=0><img src ="http://www.blogjava.net/hexuzhong/aggbug/24483.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2005-12-18 14:19 <a href="http://www.blogjava.net/hexuzhong/archive/2005/12/18/24483.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jakarta Commons学习笔记 [HttpClient] 发送Query</title><link>http://www.blogjava.net/hexuzhong/archive/2005/12/06/22729.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Tue, 06 Dec 2005 07:37:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2005/12/06/22729.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/22729.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2005/12/06/22729.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/22729.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/22729.html</trackback:ping><description><![CDATA[<P>发送Query</P>
<P>昨天学习了如何模似一个GET请求，地址:<A HREF="/hexuzhong/archive/2005/12/05/22640.html">http://www.blogjava.net/hexuzhong/archive/2005/12/05/22640.html</A></P>
<P>今天学习在这个GET请求后加上Query.在实例化一个GetMethod方法后，可以调用setQueryString()方法添加Query.下面演示了这个特性</P>
<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;recipe11_4.jsp<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;假如这是我们要模似GET并发出Query的jsp文件</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&lt;%</SPAN><SPAN style="COLOR: #000000">@&nbsp;page&nbsp;contentType</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">text/html;&nbsp;charset=utf-8</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">%&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&lt;!</SPAN><SPAN style="COLOR: #000000">DOCTYPE&nbsp;HTML&nbsp;PUBLIC&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">-//W3C//DTD&nbsp;HTML&nbsp;4.01&nbsp;Transitional//EN</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">html</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">body</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Param&nbsp;A:&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;%=</SPAN><SPAN style="COLOR: #000000">request.getParameter(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">paramA</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">%&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">br</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Param&nbsp;B:&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;%=</SPAN><SPAN style="COLOR: #000000">request.getParameter(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">paramB</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">%&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;/</SPAN><SPAN style="COLOR: #000000">body</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&lt;/</SPAN><SPAN style="COLOR: #000000">html</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Recipe11_4.java</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;url&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">http://127.0.0.1:8080/test/commons/httpclient/recipe11_4.jsp</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;HttpClient&nbsp;client&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;HttpClient();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;GetMethod&nbsp;method&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;GetMethod(url);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;模似GET方法的两个参数.<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;下面相当于?paramA=param%2520A%2520value&amp;paramB=param%2520B%2520value</SPAN><SPAN style="COLOR: #008000"><BR><IMG id=Codehighlighter1_268_763_Open_Image onclick="this.style.display='none'; Codehighlighter1_268_763_Open_Text.style.display='none'; Codehighlighter1_268_763_Closed_Image.style.display='inline'; Codehighlighter1_268_763_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_268_763_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_268_763_Closed_Text.style.display='none'; Codehighlighter1_268_763_Open_Image.style.display='inline'; Codehighlighter1_268_763_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN id=Codehighlighter1_268_763_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_268_763_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NameValuePair&nbsp;pairA&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;NameValuePair(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">paramA</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;URIUtil<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.encodeQuery(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">param&nbsp;A&nbsp;value</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NameValuePair&nbsp;pairB&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;NameValuePair(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">paramB</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;URIUtil<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.encodeQuery(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">param&nbsp;B&nbsp;value</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));<BR><IMG id=Codehighlighter1_507_522_Open_Image onclick="this.style.display='none'; Codehighlighter1_507_522_Open_Text.style.display='none'; Codehighlighter1_507_522_Closed_Image.style.display='inline'; Codehighlighter1_507_522_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_507_522_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_507_522_Closed_Text.style.display='none'; Codehighlighter1_507_522_Open_Image.style.display='inline'; Codehighlighter1_507_522_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NameValuePair[]&nbsp;pair&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;NameValuePair[]&nbsp;</SPAN><SPAN id=Codehighlighter1_507_522_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_507_522_Open_Text><SPAN style="COLOR: #000000">{&nbsp;pairA,&nbsp;pairB&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;将参数设置到url中去</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;method.setQueryString(pair);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;模似http&nbsp;GET请求</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;client.executeMethod(method);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG id=Codehighlighter1_677_760_Open_Image onclick="this.style.display='none'; Codehighlighter1_677_760_Open_Text.style.display='none'; Codehighlighter1_677_760_Closed_Image.style.display='inline'; Codehighlighter1_677_760_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_677_760_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_677_760_Closed_Text.style.display='none'; Codehighlighter1_677_760_Open_Image.style.display='inline'; Codehighlighter1_677_760_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(method.getStatusCode()&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;HttpStatus.SC_OK)&nbsp;</SPAN><SPAN id=Codehighlighter1_677_760_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_677_760_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;输出服务端响应内容(html)</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(method.getResponseBodyAsString());<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_788_814_Open_Image onclick="this.style.display='none'; Codehighlighter1_788_814_Open_Text.style.display='none'; Codehighlighter1_788_814_Closed_Image.style.display='inline'; Codehighlighter1_788_814_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_788_814_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_788_814_Closed_Text.style.display='none'; Codehighlighter1_788_814_Open_Image.style.display='inline'; Codehighlighter1_788_814_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">&nbsp;(URIException&nbsp;e)&nbsp;</SPAN><SPAN id=Codehighlighter1_788_814_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_788_814_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<BR><IMG id=Codehighlighter1_840_866_Open_Image onclick="this.style.display='none'; Codehighlighter1_840_866_Open_Text.style.display='none'; Codehighlighter1_840_866_Closed_Image.style.display='inline'; Codehighlighter1_840_866_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_840_866_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_840_866_Closed_Text.style.display='none'; Codehighlighter1_840_866_Open_Image.style.display='inline'; Codehighlighter1_840_866_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">&nbsp;(HttpException&nbsp;e)&nbsp;</SPAN><SPAN id=Codehighlighter1_840_866_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_840_866_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<BR><IMG id=Codehighlighter1_890_916_Open_Image onclick="this.style.display='none'; Codehighlighter1_890_916_Open_Text.style.display='none'; Codehighlighter1_890_916_Closed_Image.style.display='inline'; Codehighlighter1_890_916_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_890_916_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_890_916_Closed_Text.style.display='none'; Codehighlighter1_890_916_Open_Image.style.display='inline'; Codehighlighter1_890_916_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">&nbsp;(IOException&nbsp;e)&nbsp;</SPAN><SPAN id=Codehighlighter1_890_916_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_890_916_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN></DIV><BR>上面的java代码利用HttpClient类库，向web服务器提交请求recipe11_4.jsp文件，并传送paramA,paramB两个参数,服务端接收到请求后，处理这个请求，jsp文件中将取得paramA,paramB两个参数,并输出下面内容返回给客户端<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;!</SPAN><SPAN style="COLOR: #ff00ff">DOCTYPE&nbsp;HTML&nbsp;PUBLIC&nbsp;"-//W3C//DTD&nbsp;HTML&nbsp;4.01&nbsp;Transitional//EN"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">html</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">body</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Param&nbsp;A:&nbsp;param&nbsp;A&nbsp;value<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">br</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Param&nbsp;B:&nbsp;param&nbsp;B&nbsp;value<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">body</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">html</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV><img src ="http://www.blogjava.net/hexuzhong/aggbug/22729.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2005-12-06 15:37 <a href="http://www.blogjava.net/hexuzhong/archive/2005/12/06/22729.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jakarta Commons学习笔记 [HttpClient] 模似GET请求</title><link>http://www.blogjava.net/hexuzhong/archive/2005/12/05/22640.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Mon, 05 Dec 2005 14:10:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2005/12/05/22640.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/22640.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2005/12/05/22640.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/22640.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/22640.html</trackback:ping><description><![CDATA[<P>HttpClient简介<A href="/hexuzhong/archive/2005/12/05/22639.html"><BR>http://www.blogjava.net/hexuzhong/archive/2005/12/05/22639.html</A><BR><BR>模似GET请求</P>
<P>创建一个HttpClient实例,使用它执行GetMethod对象,服务端response能通过InputStream, byte[]或String访问,下面的例子演示了GetMethod的用法,将返回信息通过String访问</P>
<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;HttpClient&nbsp;client&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;HttpClient();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;待访问的url,这个程序中将用GetMethod模拟一个客户端访问这个URL</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;url&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">http://127.0.0.1:8080/test/commons/httpclient/MyJsp.jsp</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;GetMethod&nbsp;method&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;GetMethod(url);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG id=Codehighlighter1_202_454_Open_Image onclick="this.style.display='none'; Codehighlighter1_202_454_Open_Text.style.display='none'; Codehighlighter1_202_454_Closed_Image.style.display='inline'; Codehighlighter1_202_454_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_202_454_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_202_454_Closed_Text.style.display='none'; Codehighlighter1_202_454_Open_Image.style.display='inline'; Codehighlighter1_202_454_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN id=Codehighlighter1_202_454_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_202_454_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;client.executeMethod(method);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;服务端返回成功信息的话,则将服务端返回转换为String并显示</SPAN><SPAN style="COLOR: #008000"><BR><IMG id=Codehighlighter1_323_415_Open_Image onclick="this.style.display='none'; Codehighlighter1_323_415_Open_Text.style.display='none'; Codehighlighter1_323_415_Closed_Image.style.display='inline'; Codehighlighter1_323_415_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_323_415_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_323_415_Closed_Text.style.display='none'; Codehighlighter1_323_415_Open_Image.style.display='inline'; Codehighlighter1_323_415_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(method.getStatusCode()&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;HttpStatus.SC_OK)&nbsp;</SPAN><SPAN id=Codehighlighter1_323_415_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_323_415_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;response&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;method.getResponseBodyAsString();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(response);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;如果抛出HttpException则问题可能与HTTP协议有关</SPAN><SPAN style="COLOR: #008000"><BR><IMG id=Codehighlighter1_480_538_Open_Image onclick="this.style.display='none'; Codehighlighter1_480_538_Open_Text.style.display='none'; Codehighlighter1_480_538_Closed_Image.style.display='inline'; Codehighlighter1_480_538_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_480_538_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_480_538_Closed_Text.style.display='none'; Codehighlighter1_480_538_Open_Image.style.display='inline'; Codehighlighter1_480_538_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">&nbsp;(HttpException&nbsp;e)&nbsp;</SPAN><SPAN id=Codehighlighter1_480_538_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_480_538_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;如果抛出IOException则问题可能与网络状况有关</SPAN><SPAN style="COLOR: #008000"><BR><IMG id=Codehighlighter1_562_588_Open_Image onclick="this.style.display='none'; Codehighlighter1_562_588_Open_Text.style.display='none'; Codehighlighter1_562_588_Closed_Image.style.display='inline'; Codehighlighter1_562_588_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_562_588_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_562_588_Closed_Text.style.display='none'; Codehighlighter1_562_588_Open_Image.style.display='inline'; Codehighlighter1_562_588_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">&nbsp;(IOException&nbsp;e)&nbsp;</SPAN><SPAN id=Codehighlighter1_562_588_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_562_588_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<BR><IMG id=Codehighlighter1_598_715_Open_Image onclick="this.style.display='none'; Codehighlighter1_598_715_Open_Text.style.display='none'; Codehighlighter1_598_715_Closed_Image.style.display='inline'; Codehighlighter1_598_715_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_598_715_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_598_715_Closed_Text.style.display='none'; Codehighlighter1_598_715_Open_Image.style.display='inline'; Codehighlighter1_598_715_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">finally</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN id=Codehighlighter1_598_715_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_598_715_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;释放网络连接资源</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;method.releaseConnection();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;不赞成使用的方法,重新使用GetMethod,当调用这个方法的时候,全部的实例变量将重置</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;method.recycle();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN></DIV><BR>这段代码会将<A href="http://127.0.0.1:8080/test/commons/httpclient/MyJsp.jsp">http://127.0.0.1:8080/test/commons/httpclient/MyJsp.jsp</A>中内容以String输出.(html代码)<img src ="http://www.blogjava.net/hexuzhong/aggbug/22640.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2005-12-05 22:10 <a href="http://www.blogjava.net/hexuzhong/archive/2005/12/05/22640.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jakarta Commons HttpClient简介</title><link>http://www.blogjava.net/hexuzhong/archive/2005/12/05/22639.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Mon, 05 Dec 2005 14:07:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2005/12/05/22639.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/22639.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2005/12/05/22639.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/22639.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/22639.html</trackback:ping><description><![CDATA[Jakarta HttpClient是一套处理Http协议的类库,HttpClient是一个强大的,支持RFC2616(超文本传输协议,HTTP/1.1)规范, Jakarta HttpClient支持GET, POST, PUT, OPTIONS, HEAD, DELETE等方法.支持不同的认证机制,包括Basic, Digest, NTLM认证.支持HTTP和HTTPS协议,能管理session,cookie.等等<br><br><img src="http://www.blogjava.net/images/blogjava_net/hexuzhong/1137/o_httpclient_logo.png" alt="o_httpclient_logo.png" border="0" height="100" width="325"><br><img src ="http://www.blogjava.net/hexuzhong/aggbug/22639.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2005-12-05 22:07 <a href="http://www.blogjava.net/hexuzhong/archive/2005/12/05/22639.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jakarta Commons学习笔记 [BeanUtils] 动态创建bean</title><link>http://www.blogjava.net/hexuzhong/archive/2005/12/01/22141.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Thu, 01 Dec 2005 09:54:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2005/12/01/22141.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/22141.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2005/12/01/22141.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/22141.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/22141.html</trackback:ping><description><![CDATA[<P>动态创建bean</P>
<P>使用DynaBean,可以在程序运行时运态创建一个bean.(像struts中的ActionFrom有动态创建bean这个功能等)这个创建的bean也能被Commons BeanUtils中的类操作.下面的代码演示这个特性</P>
<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;动态创建bean中含有的属性,这个例子中有name和age这两个属性</SPAN><SPAN style="COLOR: #008000"><BR><IMG id=Codehighlighter1_90_177_Open_Image onclick="this.style.display='none'; Codehighlighter1_90_177_Open_Text.style.display='none'; Codehighlighter1_90_177_Closed_Image.style.display='inline'; Codehighlighter1_90_177_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_90_177_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_90_177_Closed_Text.style.display='none'; Codehighlighter1_90_177_Open_Image.style.display='inline'; Codehighlighter1_90_177_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;DynaProperty[]&nbsp;beanProperties&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;DynaProperty[]&nbsp;</SPAN><SPAN id=Codehighlighter1_90_177_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_90_177_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;DynaProperty(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">name</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;String.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">),<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;DynaProperty(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">age</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;Integer.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">),<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;BasicDynaClass&nbsp;personClass&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;BasicDynaClass(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">person</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;BasicDynaBean.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">,&nbsp;beanProperties);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;生成这个bean的一个实例</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;DynaBean&nbsp;person&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;personClass.newInstance();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;设置name属性,age属性的值</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;person.set(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">name</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">hxz</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;person.set(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">age</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Integer(</SPAN><SPAN style="COLOR: #000000">21</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;输出<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;hxz<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;21</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(person.get(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">name</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(person.get(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">age</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;输出&nbsp;21<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Commons&nbsp;BeanUtils包中的类也能操作这个动态生成的bean</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(PropertyUtils.getSimpleProperty(person,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">name</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));</SPAN></DIV><BR>// 刚刚把DynaBean中方法介绍写出来了,没保存+掉线.. 郁闷<img src ="http://www.blogjava.net/hexuzhong/aggbug/22141.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2005-12-01 17:54 <a href="http://www.blogjava.net/hexuzhong/archive/2005/12/01/22141.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jakarta Commons学习笔记 [BeanUtils] 创建与bean属性对应的Map</title><link>http://www.blogjava.net/hexuzhong/archive/2005/11/30/21925.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Wed, 30 Nov 2005 03:32:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2005/11/30/21925.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/21925.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2005/11/30/21925.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/21925.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/21925.html</trackback:ping><description><![CDATA[<P>创建与bean属性对应的Map</P>
<P>使用PropertyUtils.describe()生成Map实例,其中包含了源bean中所有可读的属性.下面的代码片段演示了这个特性</P>
<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;Person&nbsp;author&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Person();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;author.setName(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Timothy&nbsp;M.&nbsp;O'Brien</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Book&nbsp;book&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Book();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;book.setName(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Jakarta&nbsp;Commons&nbsp;Cookbook</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;book.setAuthor(author);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;取得book中的所有可读属性,返回到map中</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;Map&nbsp;bookMap&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;PropertyUtils.describe(book);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Book类中包含一个Author类型的属性<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;取bookMap中的author&nbsp;bean,并将其所有可读属性返回到authorMap中</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;Map&nbsp;authorMap&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;PropertyUtils.describe(bookMap.get(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">author</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;输出<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Book&nbsp;Name:&nbsp;Jakarta&nbsp;Commons&nbsp;Cookbook<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Author&nbsp;Name:&nbsp;Timothy&nbsp;M.&nbsp;O'Brien</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Book&nbsp;Name:&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;bookMap.get(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">name</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Author&nbsp;Name:&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;authorMap.get(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">name</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));</SPAN></DIV><BR>PropertyUtils.describe()方法将返回bean中每个可读的属性都添加到Map中去.如果值为设置,将返回默认值,在上面的例子中假如Book类中还有个Integer型的page属性,代表书籍页数.在没设置的情况下,将返回null.如果page属性为int型,则将返回0<img src ="http://www.blogjava.net/hexuzhong/aggbug/21925.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2005-11-30 11:32 <a href="http://www.blogjava.net/hexuzhong/archive/2005/11/30/21925.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jakarta Commons学习 [BeanUtils] 测试bean属性是否可读/写</title><link>http://www.blogjava.net/hexuzhong/archive/2005/11/29/21811.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Tue, 29 Nov 2005 04:47:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2005/11/29/21811.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/21811.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2005/11/29/21811.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/21811.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/21811.html</trackback:ping><description><![CDATA[测试bean属性是否可读/写<BR><BR>使用PropertyUtils.isReadable()和PropertyUtils.isWritable()可检测bean属性是否可读,可写.<BR>下面的代码片段测试Book的name属性是否可读/写<BR><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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;Book&nbsp;book&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Book();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;book.setName(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Jakarta&nbsp;Commons&nbsp;Cookbook</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;book.getName();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">boolean</SPAN><SPAN style="COLOR: #000000">&nbsp;nameReadable&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;PropertyUtils.isReadable(book,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">name</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">boolean</SPAN><SPAN style="COLOR: #000000">&nbsp;nameWritable&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;PropertyUtils.isWriteable(book,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">name</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;输出<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Is&nbsp;name&nbsp;readable?&nbsp;true<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Is&nbsp;name&nbsp;writable?&nbsp;true</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Is&nbsp;name&nbsp;readable?&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;nameReadable);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Is&nbsp;name&nbsp;writable?&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;nameWritable);</SPAN></DIV><BR>Book类还是前面的那个例子,因为book类有name的getter/setter方法,所以测试都返回true.<BR>除了测试简单的属性外,isReadable()和isWritable()方法还有测试嵌套,带索引,map类型的属性(访问时写法都和前面一样).<BR>下面的片段测试一个嵌套属性的可读写性.<BR><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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;Person&nbsp;author&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Person();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;author.setName(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Timothy&nbsp;M.&nbsp;O'Brien</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Book&nbsp;book&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Book();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;book.setAuthor(author);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">boolean</SPAN><SPAN style="COLOR: #000000">&nbsp;authorReadable&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;PropertyUtils.isReadable(book,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">author.name</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">boolean</SPAN><SPAN style="COLOR: #000000">&nbsp;authorWritable&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;PropertyUtils.isWriteable(book,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">author.name</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;因为Person的name属性也有相关的getter/setter方法,所以都输出true<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Is&nbsp;author's&nbsp;name&nbsp;readable?&nbsp;true<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Is&nbsp;author's&nbsp;name&nbsp;writable?&nbsp;true</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Is&nbsp;author's&nbsp;name&nbsp;readable?&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;authorReadable);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Is&nbsp;author's&nbsp;name&nbsp;writable?&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;authorWritable);</SPAN></DIV><BR><img src ="http://www.blogjava.net/hexuzhong/aggbug/21811.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2005-11-29 12:47 <a href="http://www.blogjava.net/hexuzhong/archive/2005/11/29/21811.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jakarta Commons学习笔记 [BeanUtils] 克隆bean</title><link>http://www.blogjava.net/hexuzhong/archive/2005/11/28/21701.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Mon, 28 Nov 2005 09:44:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2005/11/28/21701.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/21701.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2005/11/28/21701.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/21701.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/21701.html</trackback:ping><description><![CDATA[使用BeanUtils.cloneBean()方法克隆一个bean,这个方法通过默认构造函数建立一个bean的新实例,然后拷贝每一个属性到这个新的bean中.下面的代码片段演示这个东东.<BR><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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;Book&nbsp;book1&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Book();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;book1.setName(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Jakarta&nbsp;Commons&nbsp;Cookbook</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Book&nbsp;book2&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(Book)BeanUtils.cloneBean(book1);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;输出<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Jakarta&nbsp;Commons&nbsp;Cookbook</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(book2.getName());</SPAN></DIV><BR>cloneBean()工作步骤可以理解为先建立一个bean的新实例,然后调用PropertyUtils.copyProperties()将源bean中全部可读的属性传送到新的bean中去. 看下面的代码<BR><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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;Book&nbsp;book1&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Book();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;book1.setName(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Jakarta&nbsp;Commons&nbsp;Cookbook</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Book&nbsp;book2&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;book1.getClass().newInstance();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;PropertyUtils.copyProperties(book2,&nbsp;book1);</SPAN></DIV><BR>目前感觉cloneBean()和copyProperties()有什么内在的区别,赋值的时候也是赋references给新的bean.<BR>看下面的代码(似乎就是代码量少了一点 -__-!!):<BR><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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;Person&nbsp;author&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Person();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;author.setName(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Timothy&nbsp;M.&nbsp;O'Brien</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Book&nbsp;book1&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Book();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;book1.setName(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Jakarta&nbsp;Commons&nbsp;Cookbook</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;book1.setAuthor(author);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Book&nbsp;book2&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(Book)BeanUtils.cloneBean(book1);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(book2.getName());<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;这两个对象的references还是一样,和copyProperties()一样<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;输出:&nbsp;tag</SPAN><SPAN style="COLOR: #008000"><BR><IMG id=Codehighlighter1_362_394_Open_Image onclick="this.style.display='none'; Codehighlighter1_362_394_Open_Text.style.display='none'; Codehighlighter1_362_394_Closed_Image.style.display='inline'; Codehighlighter1_362_394_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_362_394_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_362_394_Closed_Text.style.display='none'; Codehighlighter1_362_394_Open_Image.style.display='inline'; Codehighlighter1_362_394_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(book1.getAuthor()&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;book2.getAuthor())&nbsp;</SPAN><SPAN id=Codehighlighter1_362_394_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_362_394_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">tag</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN></DIV><img src ="http://www.blogjava.net/hexuzhong/aggbug/21701.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2005-11-28 17:44 <a href="http://www.blogjava.net/hexuzhong/archive/2005/11/28/21701.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jakarta Commons学习笔记 [BeanUtils] 拷贝bean属性</title><link>http://www.blogjava.net/hexuzhong/archive/2005/11/27/21558.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Sun, 27 Nov 2005 05:47:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2005/11/27/21558.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/21558.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2005/11/27/21558.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/21558.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/21558.html</trackback:ping><description><![CDATA[<P>拷贝bean属性</P>
<P>使用PropertyUtils.copyProperties()拷贝一个bean中的属性到另一个bean中,第一个参数是目标bean,第二个参数是源bean,代码片段见下</P>
<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;Book&nbsp;srcBook&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Book();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;srcBook.setName(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Jakarta&nbsp;Commons&nbsp;Cookbook</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Book&nbsp;destBook&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Book();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;PropertyUtils.copyProperties(destBook,&nbsp;srcBook);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;输出&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Jakarta&nbsp;Commons&nbsp;Cookbook</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(destBook.getName());</SPAN></DIV><BR>PropertyUtils.copyProperties()将检索源bean中所有的属性,然后将其值分配给目标bean中相同的属性,如果上面的例子中Book bean有一个author属性,类型是Person,这个方法将分配其的references给destBook,也就是说copyProperties()方法不会克隆属性的值.看下面的代码片段<BR><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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;Person&nbsp;author&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Person();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;author.setName(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Timothy&nbsp;M.&nbsp;O'Brien</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Book&nbsp;srcBook&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Book();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;srcBook.setName(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Jakarta&nbsp;Commons&nbsp;Cookbook</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;srcBook.setAuthor(author);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Book&nbsp;destBook&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Book();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;PropertyUtils.copyProperties(destBook,&nbsp;srcBook);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;结果输出<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Author&nbsp;objects&nbsp;identical</SPAN><SPAN style="COLOR: #008000"><BR><IMG id=Codehighlighter1_351_404_Open_Image onclick="this.style.display='none'; Codehighlighter1_351_404_Open_Text.style.display='none'; Codehighlighter1_351_404_Closed_Image.style.display='inline'; Codehighlighter1_351_404_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_351_404_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_351_404_Closed_Text.style.display='none'; Codehighlighter1_351_404_Open_Image.style.display='inline'; Codehighlighter1_351_404_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(srcBook.getAuthor()&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;destBook.getAuthor())&nbsp;</SPAN><SPAN id=Codehighlighter1_351_404_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_351_404_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Author&nbsp;objects&nbsp;identical</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN></DIV><BR>copyProperties()方法也能将Map中的内容分酌给bean,如果key同目标bean的属性名相同的话<BR><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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;Map&nbsp;srcMap&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;HashMap();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;srcMap.put(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">name</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Jakarta&nbsp;Commons&nbsp;Cookbook</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Book&nbsp;destBook&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Book();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;PropertyUtils.copyProperties(destBook,&nbsp;srcMap);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;输出<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Jakarta&nbsp;Commons&nbsp;Cookbook</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(destBook.getName());</SPAN></DIV><img src ="http://www.blogjava.net/hexuzhong/aggbug/21558.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2005-11-27 13:47 <a href="http://www.blogjava.net/hexuzhong/archive/2005/11/27/21558.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jakarta Commons学习笔记 [BeanUtils] 确定Bean属性的类型</title><link>http://www.blogjava.net/hexuzhong/archive/2005/11/26/21498.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Sat, 26 Nov 2005 03:48:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2005/11/26/21498.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/21498.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2005/11/26/21498.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/21498.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/21498.html</trackback:ping><description><![CDATA[<P>确定Bean属性的类型</P>
<P>使用PropertyUtils.getPropertyType()确定bean属性的类型,这个方法返回 Class 对象使用getter方法表述它的类型,下面的代码片段演示了从Book bean中检索author属性的类型</P>
<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;直接取book的author属性类型</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;Book&nbsp;book&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Book();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Class&nbsp;type&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;PropertyUtils.getPropertyType(book,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">author</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;author属性类型为&nbsp;Author</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(type.getName());<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;输出:&nbsp;commons.beanutils.Person</SPAN></DIV><BR>使用getPropertyType()也能取出嵌套的bean属性类型,像先前取混合类型的值一样,看下面的代码:<BR><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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;演示从嵌套属性中取出其值类型</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;Chapter&nbsp;chapter&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Chapter();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;下面将出个这个name属性的类型,String</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;chapter.setName(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Chapter&nbsp;3&nbsp;BeanUtils</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;List&nbsp;chapters&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;ArrayList();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;chapters.add(chapter);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Book&nbsp;book2&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Book();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;book2.setChapters(chapters);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Class&nbsp;type2&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;PropertyUtils.getPropertyType(book2,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">chapters[0].name</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;chapter的name属性类型为String</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(type2.getName());<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;输出<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;java.lang.String</SPAN></DIV><BR>PropertyUtils类还包含另外一个方法检索方法PropertyUtils.getPropertyDescriptor(),这个方法返回PropertyDescriptor对象提供访问bean的read和write方法. 看下面的代码<BR><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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;chapters[0].name&nbsp;相当于<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;book2.getChapters().get(0).getName();</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;PropertyDescriptor&nbsp;pd&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;PropertyUtils.getPropertyDescriptor(book2,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">chapters[0].name</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Class&nbsp;type3&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;pd.getPropertyType();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Method&nbsp;writeMethod&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;pd.getWriteMethod();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Method&nbsp;readMethod&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;pd.getReadMethod();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">writeMethod:&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;writeMethod.getName());<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">readMethod:&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;readMethod.getName());<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;输出<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;writeMethod:&nbsp;setName<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;readMethod:&nbsp;getName</SPAN></DIV><img src ="http://www.blogjava.net/hexuzhong/aggbug/21498.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2005-11-26 11:48 <a href="http://www.blogjava.net/hexuzhong/archive/2005/11/26/21498.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jakarta Commons学习笔记 [BeanUtils] 访问"混合"类型的bean属性</title><link>http://www.blogjava.net/hexuzhong/archive/2005/11/25/21449.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Fri, 25 Nov 2005 11:03:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2005/11/25/21449.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/21449.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2005/11/25/21449.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/21449.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/21449.html</trackback:ping><description><![CDATA[<P>访问"混合"类型的bean属性</P>
<P>使用PropertyUtils.getProperty()访问任何类型的bean属性(嵌套,索引,map等).<BR>下面的代码片段演示了访问简单的属性population,嵌套的map属性cities,索引属性regions</P>
<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;City&nbsp;richmond&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;City();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;richmond.setName(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Richmond</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;richmond.setPopulation(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Long(</SPAN><SPAN style="COLOR: #000000">500000</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Map&nbsp;cities&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;HashMap();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cities.put(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">richmond</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;richmond);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Region&nbsp;midAtlantic&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Region();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;midAtlantic.setName(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Mid-Atlantic</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;midAtlantic.setCities(cities);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List&nbsp;regions&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;ArrayList();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;regions.add(midAtlantic);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Country&nbsp;country&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Country();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;country.setName(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">United&nbsp;States</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;country.setRegions(regions);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;检索richmod实例的population属性</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Long&nbsp;population&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(Long)PropertyUtils.getProperty(country,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">regions[0].cities(richmond).population</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;输出&nbsp;50000</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(population);</SPAN></DIV>
<P>上面的getProperty()片段想当于调用以下方法:<BR>Region region = (Region)country.getRegions().get(0);<BR>City city = region.getCities().get("richmond");<BR>Long population = city.getPopulation();</P>
<P>当调用getProperty()方法时,系统会从你提供的参数中切分"."号,分析并调用合适的方法如:<BR>getSimpleProperty(), getNestedProperty(), getIndexedProperty(), getMappedProperty().<BR>&nbsp;&nbsp;<BR></P><img src ="http://www.blogjava.net/hexuzhong/aggbug/21449.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2005-11-25 19:03 <a href="http://www.blogjava.net/hexuzhong/archive/2005/11/25/21449.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jakarta Commons学习笔记 [BeanUtils] 设置/检索带map类型的Bean</title><link>http://www.blogjava.net/hexuzhong/archive/2005/11/24/21298.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Thu, 24 Nov 2005 08:08:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2005/11/24/21298.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/21298.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2005/11/24/21298.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/21298.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/21298.html</trackback:ping><description><![CDATA[<P>设置/检索带map类型的Bean</P>
<P>使用PropertyUtils.getMappedProperty()/setMappedProperty()提供了从Bean的map类型中取得其值的功能，<BR>下面的代码片段演示了这个功能。</P>
<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">Room&nbsp;dining&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Room();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dining.setArea(</SPAN><SPAN style="COLOR: #000000">20</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dining.setCarpeted(</SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dining.setFurnished(</SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Room&nbsp;bed&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Room();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bed.setArea(</SPAN><SPAN style="COLOR: #000000">25</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bed.setCarpeted(</SPAN><SPAN style="COLOR: #0000ff">false</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bed.setFurnished(</SPAN><SPAN style="COLOR: #0000ff">false</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Map&nbsp;rooms&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;HashMap();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rooms.put(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Dining&nbsp;Room</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;dining);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Apartment&nbsp;apartment&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Apartment();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;apartment.setRooms(rooms);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;为rooms这个map类型添加一个bed对象,map的key为&nbsp;Bed&nbsp;Room</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PropertyUtils.setMappedProperty(apartment,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">rooms</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Bed&nbsp;Room</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;bed);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;检索dining&nbsp;room对象<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;相当于调用&nbsp;apartment.getRooms().get("Dining&nbsp;Room");</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Room&nbsp;room&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(Room)&nbsp;PropertyUtils.getMappedProperty(apartment,<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">rooms(Dining&nbsp;Room)</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(room.getArea());<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;检索apartment对象中rooms属性的bed&nbsp;room值，通过getMappedProperty()方法的另一种版本</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Room&nbsp;room2&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(Room)&nbsp;PropertyUtils.getMappedProperty(apartment,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">rooms</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Bed&nbsp;Room</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(room2.getArea());<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;输出<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;20<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;25</SPAN></DIV><img src ="http://www.blogjava.net/hexuzhong/aggbug/21298.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2005-11-24 16:08 <a href="http://www.blogjava.net/hexuzhong/archive/2005/11/24/21298.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jakarta Commons学习笔记 [BeanUtils] 设置/检索带索引属性的Bean</title><link>http://www.blogjava.net/hexuzhong/archive/2005/11/23/21115.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Wed, 23 Nov 2005 05:25:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2005/11/23/21115.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/21115.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2005/11/23/21115.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/21115.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/21115.html</trackback:ping><description><![CDATA[<P>设置/检索带索引属性的Bean</P>
<P>使用PorpertyUtils.getIndexedProperty()/setIndexedProperty()方法可以检索指定索引的array或list属性。<BR>假如先前的Book类有一个chapters属性，类型为List。下面的代码片段演示了上面的方法的使用</P>
<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%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">Book&nbsp;book&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Book();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Chapter&nbsp;chapter1&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Chapter();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Chapter&nbsp;chapter2&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Chapter();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chapter1.setName(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">BeanUtils</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chapter2.setName(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">xml</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;book.getChapters().add(chapter1);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">先添加chapter1两次，如只添加一次的话，list中只存在一个元素，在设置他时，将出现IndexOutOfBoundsException异常</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;book.getChapters().add(chapter1);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">设置chapters中第一个索引元素为&nbsp;chapter2</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PropertyUtils.setIndexedProperty(book,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">chapters[1]</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;chapter2);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Chapter&nbsp;x&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(Chapter)PropertyUtils.getIndexedProperty(book,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">chapters[0]</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Chapter&nbsp;y&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(Chapter)PropertyUtils.getIndexedProperty(book,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">chapters[1]</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(x.getName());<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;可以看到，已经成功将&nbsp;chapter2&nbsp;设置到&nbsp;chapters&nbsp;中去了</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(y.getName());<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;输出</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BeanUtils<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xml</SPAN></DIV><BR>上面的方法通过getter/setter两个方法，传入两个参数完成了工作。但这并不是一个好的格式。<BR>假如你使用的是getIndexedProperty(book, "chapters[a]"), getIndexedProperty(book, "chapters]1[");<BR>将会抛出IllegalArgumentException异常，因为没有索引是integer值。<BR>我们可以使用另一种形式来设置，检索。<BR>//设置chapters属性的第2个值为chapter2 (下标从0开始)<BR>PropertyUtils.setIndexedProperty(book, "chapters", 1, chapter2);<BR>//取得chapters属性的第1个值<BR>PropertyUtils.getIndexedProperty(book, "chapters", 0);<BR><img src ="http://www.blogjava.net/hexuzhong/aggbug/21115.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2005-11-23 13:25 <a href="http://www.blogjava.net/hexuzhong/archive/2005/11/23/21115.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jakarta Commons学习笔记 [BeanUtils] 访问嵌套bean属性</title><link>http://www.blogjava.net/hexuzhong/archive/2005/11/22/21002.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Tue, 22 Nov 2005 09:17:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2005/11/22/21002.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/21002.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2005/11/22/21002.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/21002.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/21002.html</trackback:ping><description><![CDATA[<p>访问嵌套bean属性</p>
<p>使用PropertyUtils.getNestedProperty()检索嵌套的bean属性,使用"."号识别嵌套的bean属性.<br>例如one.two.three.four的属性有三层,four是three的属性,而three又是two的属性,two又是one的属性.</p>
<p>下面来看一个代码片段,还是围绕Person等类展开<br></p>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"><span style="color: rgb(0, 0, 0);">Book&nbsp;book&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;Book();<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;book.setName(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">富爸爸，穷爸爸</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;Person&nbsp;person&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;Person();<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;person.setName(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Robert&nbsp;T.Kiyosaki</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;book.setAuthor(person);<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;catch&nbsp;exception<img src="http://www.blogjava.net/images/dot.gif"></span><span style="color: rgb(0, 128, 0);"><br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"></span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;authorName&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;(String)PropertyUtils.getNestedProperty(book,&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">author.name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Article:&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;book.getName());<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Author:&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;authorName);</span></div>
<p>author是book类的一个属性, 它是Person类型,有一个name属性.下面是它们的类图<br><img alt="r_无标题.bmp" src="http://www.blogjava.net/images/blogjava_net/hexuzhong/1137/r_%E6%97%A0%E6%A0%87%E9%A2%98.bmp" border="0" height="46" width="193"><br><br>上面的代码片段中我们使用getNestedProperty(book, "author.name")来取得book类的author属性的name的值( 好拗口 :~( )</p>
<p>来一个更深的嵌套代码片段:<br></p>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"><span style="color: rgb(0, 0, 0);">Book&nbsp;book&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;Book();<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;book.setName(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">富爸爸，穷爸爸</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;Person&nbsp;person&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;Person();<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;person.setName(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Robert&nbsp;T.Kiyosaki</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"><br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;Address&nbsp;address&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;Address();<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;address.setCity(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">N/A</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;person.setAddress(address);<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;book.setAuthor(person);<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;cityName&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;(String)PropertyUtils.getNestedProperty(book,&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">author.address.city</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">City:&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;cityName);</span></div><br>Book类有一个Author类属性, Author类有一个Address类属性, Address有一个city属性.<br>通过 author.address.city 来取得这个嵌套bean的属性.<img src ="http://www.blogjava.net/hexuzhong/aggbug/21002.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2005-11-22 17:17 <a href="http://www.blogjava.net/hexuzhong/archive/2005/11/22/21002.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jakarta Commons学习 [BeanUtils] 访问简单的bean属性</title><link>http://www.blogjava.net/hexuzhong/archive/2005/11/22/20982.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Tue, 22 Nov 2005 08:31:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2005/11/22/20982.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/20982.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2005/11/22/20982.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/20982.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/20982.html</trackback:ping><description><![CDATA[<p>访问简单的bean属性<br></p>
<p>PropertyUtils.getSimpleProperty()/setSimpleProperty()方法提供了通过名字访问/设置bean的属性,通过提供属性的名字返回它的值.<br>下面的代码片段演示了使用这个方法检索 Person 类 name 属性.<br></p>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;Person&nbsp;person&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;Person();<br><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;person.setName(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Ben</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br><img id="Codehighlighter1_60_331_Open_Image" onclick="this.style.display='none'; Codehighlighter1_60_331_Open_Text.style.display='none'; Codehighlighter1_60_331_Closed_Image.style.display='inline'; Codehighlighter1_60_331_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_60_331_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_60_331_Closed_Text.style.display='none'; Codehighlighter1_60_331_Open_Image.style.display='inline'; Codehighlighter1_60_331_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span id="Codehighlighter1_60_331_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.blogjava.net/images/dot.gif"></span><span id="Codehighlighter1_60_331_Open_Text"><span style="color: rgb(0, 0, 0);">{<br><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PropertyUtils.setSimpleProperty(person,&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">age</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;Integer(</span><span style="color: rgb(0, 0, 0);">21</span><span style="color: rgb(0, 0, 0);">));<br><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;name&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;(String)PropertyUtils.getSimpleProperty(person,&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Integer&nbsp;age&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;(Integer)PropertyUtils.getSimpleProperty(person,&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">age</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(name);<br><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(age);<br><img id="Codehighlighter1_366_392_Open_Image" onclick="this.style.display='none'; Codehighlighter1_366_392_Open_Text.style.display='none'; Codehighlighter1_366_392_Closed_Image.style.display='inline'; Codehighlighter1_366_392_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_366_392_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_366_392_Closed_Text.style.display='none'; Codehighlighter1_366_392_Open_Image.style.display='inline'; Codehighlighter1_366_392_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);">&nbsp;(IllegalAccessException&nbsp;e)&nbsp;</span><span id="Codehighlighter1_366_392_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.blogjava.net/images/dot.gif"></span><span id="Codehighlighter1_366_392_Open_Text"><span style="color: rgb(0, 0, 0);">{<br><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br><img id="Codehighlighter1_430_456_Open_Image" onclick="this.style.display='none'; Codehighlighter1_430_456_Open_Text.style.display='none'; Codehighlighter1_430_456_Closed_Image.style.display='inline'; Codehighlighter1_430_456_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_430_456_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_430_456_Closed_Text.style.display='none'; Codehighlighter1_430_456_Open_Image.style.display='inline'; Codehighlighter1_430_456_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);">&nbsp;(InvocationTargetException&nbsp;e)&nbsp;</span><span id="Codehighlighter1_430_456_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.blogjava.net/images/dot.gif"></span><span id="Codehighlighter1_430_456_Open_Text"><span style="color: rgb(0, 0, 0);">{<br><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br><img id="Codehighlighter1_490_516_Open_Image" onclick="this.style.display='none'; Codehighlighter1_490_516_Open_Text.style.display='none'; Codehighlighter1_490_516_Closed_Image.style.display='inline'; Codehighlighter1_490_516_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_490_516_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_490_516_Closed_Text.style.display='none'; Codehighlighter1_490_516_Open_Image.style.display='inline'; Codehighlighter1_490_516_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);">&nbsp;(NoSuchMethodException&nbsp;e)&nbsp;</span><span id="Codehighlighter1_490_516_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.blogjava.net/images/dot.gif"></span><span id="Codehighlighter1_490_516_Open_Text"><span style="color: rgb(0, 0, 0);">{<br><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></div>
<p><br>代码比较简单,值得注意的是那些异常处理,当于属性对应的名字的getter方法不可访问时(比如果private)IllegalAccessException异常产生,当getter方法本身抛出异常时,InvocationTargetException异常产生,当给定的名字属性不存在时,NoSuchMethodException异常产生,比如说Person类不存在getAddress()方法,而你又使用了getSimpleProperty(person, "address");</p>
<p>简单的使用这些方法,还不如来得getXXX()直接,但这种方法将你的代码绑定在编译期,如果想在运行期动态的检索,设置想关的属性,使用BeanUtils类库就比较合适了.比如说在Struts等这些框架中</p><img src ="http://www.blogjava.net/hexuzhong/aggbug/20982.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2005-11-22 16:31 <a href="http://www.blogjava.net/hexuzhong/archive/2005/11/22/20982.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>解决hibernate+mysql中文问题</title><link>http://www.blogjava.net/hexuzhong/archive/2005/08/23/10762.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Tue, 23 Aug 2005 00:55:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2005/08/23/10762.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/10762.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2005/08/23/10762.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/10762.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/10762.html</trackback:ping><description><![CDATA[<P>在网上有很多这方面文章,依照上面也解决过,但是修改了mysql的配置文件my.ini.感觉在部署时不是很爽.</P>
<P>这里给出另一种解决方法(mysql-4.1.11).低版本的mysql似乎没出现过中文问题(mysql-4.0.17). :)</P>
<P>1.添加一个过滤器,将字符集编码设为UTF-8.<BR>修改web.xml:</P>
<P>&nbsp;&lt;filter&gt;<BR>&nbsp;&nbsp;&lt;filter-name&gt;SetCharacterEncoding&lt;/filter-name&gt;<BR>&nbsp;&nbsp;&lt;filter-class&gt;hxz.filter.SetEncodingFilter&lt;/filter-class&gt;<BR>&nbsp;&nbsp;&lt;init-param&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;param-name&gt;encoding&lt;/param-name&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;param-value&gt;UTF-8&lt;/param-value&gt;<BR>&nbsp;&nbsp;&lt;/init-param&gt;<BR>&nbsp;&lt;/filter&gt;<BR>&nbsp;<BR>&nbsp;&lt;filter-mapping&gt;<BR>&nbsp;&nbsp;&lt;filter-name&gt;SetCharacterEncoding&lt;/filter-name&gt;<BR>&nbsp;&nbsp;&lt;url-pattern&gt;/*&lt;/url-pattern&gt;<BR>&nbsp;&lt;/filter-mapping&gt;</P>
<P>新建一个过滤器:<BR>package hxz.filter;</P>
<P>import java.io.IOException;</P>
<P>import javax.servlet.*;</P>
<P>public class SetEncodingFilter implements Filter {<BR>&nbsp;<BR>&nbsp;// default character encoding<BR>&nbsp;String defaultEncoding = "UTF-8";&nbsp;<BR>&nbsp;<BR>&nbsp;public void init(FilterConfig config) throws ServletException {<BR>&nbsp;&nbsp;String encoding = config.getInitParameter("encoding");<BR>&nbsp;&nbsp;if (encoding != null) {<BR>&nbsp;&nbsp;&nbsp;defaultEncoding = encoding;<BR>&nbsp;&nbsp;}<BR>&nbsp;}</P>
<P>&nbsp;public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {<BR>&nbsp;&nbsp;request.setCharacterEncoding(defaultEncoding);<BR>&nbsp;&nbsp;chain.doFilter(request, response);<BR>&nbsp;}</P>
<P>&nbsp;public void destroy() {<BR>&nbsp;&nbsp;defaultEncoding = null;<BR>&nbsp;}</P>
<P>}</P>
<P>2.修改hibernate配置文件:<BR>&lt;property name="url"&gt;<BR>&nbsp; &lt;value&gt;jdbc:mysql://localhost:3306/test?useUnicode=true&amp;amp;characterEncoding=UTF-8&lt;/value&gt;<BR>&lt;/property&gt;<BR>注意后面的:useUnicode=true&amp;amp;characterEncoding=UTF-8, 在xml中&amp;要改为;amp;</P>
<P>3.在新版本中mysql建表时,你可以选择一种字符集,将它设为utf-8.<BR>jsp或servlet中把字符集改为UTF-8.</P>
<P>4.trying...</P>
<P>&nbsp;</P><img src ="http://www.blogjava.net/hexuzhong/aggbug/10762.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2005-08-23 08:55 <a href="http://www.blogjava.net/hexuzhong/archive/2005/08/23/10762.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>利用Myeclipse快速开发struts应用程序</title><link>http://www.blogjava.net/hexuzhong/archive/2005/07/06/7218.html</link><dc:creator>HexUzHoNG</dc:creator><author>HexUzHoNG</author><pubDate>Wed, 06 Jul 2005 10:09:00 GMT</pubDate><guid>http://www.blogjava.net/hexuzhong/archive/2005/07/06/7218.html</guid><wfw:comment>http://www.blogjava.net/hexuzhong/comments/7218.html</wfw:comment><comments>http://www.blogjava.net/hexuzhong/archive/2005/07/06/7218.html#Feedback</comments><slash:comments>42</slash:comments><wfw:commentRss>http://www.blogjava.net/hexuzhong/comments/commentRss/7218.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hexuzhong/services/trackbacks/7218.html</trackback:ping><description><![CDATA[<P>
<TABLE width="100%" border=0>
<TBODY>
<TR>
<TD>头疼，又有几天没更新blog了,以此文来充实我那没有什么内容的blog。不说废话快速进入正题吧。PS：本文是myeclipse帮助文档的中文简化版。 ^___^ <BR>本人是struts初学者，如有错误请多指教。</TD></TR>
<TR>
<TD>&nbsp;</TD></TR>
<TR>
<TD>
<P>开发环境：<BR>jdk5.0<BR>eclipse3.1M7 (观众问：为啥还在用eclipse3.1M7呢？答曰：没办法，偶奶奶家还是拨号上网。^*^)<BR>myeclipse3.84<BR>tomcat5.0.28</P></TD></TR>
<TR>
<TD>&nbsp;</TD></TR>
<TR>
<TD>
<P>简介：<BR>文本主要介绍用myeclipse的struts designer（图形化开发环境）开发一个简单的用户登录程序片段。<BR>主要包括2个jsp文件、一个ActionForm、一个Action等其它<BR>userLogin.jsp(用户登录及错误提示页面) userLoginSuccess.jsp(提示登录成功页面)<BR>UserLoginForm.java(ActionForm,存放用户提交信息)<BR>UserLoginAction.java(Action,简单的处理用户登录事件) <BR></P></TD></TR>
<TR>
<TD>&nbsp;</TD></TR>
<TR>
<TD>开始吧</TD></TR>
<TR>
<TD>
<P>首先我们先建立一个j2ee的web project.如图1:<BR><IMG height=500 alt=o_1.JPG src="http://www.blogjava.net/images/blogjava_net/hexuzhong/2034/o_1.JPG" width=525 border=0></P></TD></TR></TBODY></TABLE></P>点击next,Project name输入LoginDemo,其余保持默认,点击finish.<BR>在package explorer下,就可以看到我们的项目了,然后给这个项目添加Struts框架必要的文件.在我们项目名上点击右键,选择MyEclipes --&gt; Add Struts Capabilities...弹出对话框图2：<BR><IMG height=442 alt=o_2.JPG src="http://www.blogjava.net/images/blogjava_net/hexuzhong/2034/o_2.JPG" width=719 border=0><BR>其中<SPAN class=style1><FONT color=#0000ff>Struts config path</FONT></SPAN>就是我们的struts配置文件，<SPAN class=style1><FONT color=#0000ff>URL pattern</FONT></SPAN>我们选择*.do，<SPAN class=style1><FONT color=#0000ff>Default application resource</FONT></SPAN>为我们默认的资源文件地方，你可以选择它的存储位置，我们在这里保持默认。点击Finish后，项目结构类似于图3：<BR><IMG height=644 alt=o_3.JPG src="http://www.blogjava.net/images/blogjava_net/hexuzhong/2034/o_3.JPG" width=297 border=0><BR>
<P>现在就来开始我们的例子吧。首先修改/WEB-INF/web.xml文件,为其添加标签库(在使用中发现，不添加也能成功。但为了保持书上一致，还是添加安全些。hoho~~)将下面代码添加至 &lt;/webapp&gt; 上面：<BR><BR>&lt;taglib&gt;<BR>&lt;taglib-uri&gt;/tags/struts-html&lt;/taglib-uri&gt;<BR>&lt;taglib-location&gt;/WEB-INF/struts-html.tld&lt;/taglib-location&gt;<BR>&lt;/taglib&gt;</P>
<P>&lt;taglib&gt;<BR>&lt;taglib-uri&gt;/tags/struts-bean&lt;/taglib-uri&gt;<BR>&lt;taglib-location&gt;/WEB-INF/struts-bean.tld&lt;/taglib-location&gt;<BR>&lt;/taglib&gt;</P>
<P>&lt;taglib&gt;<BR>&lt;taglib-uri&gt;/tags/struts-logic&lt;/taglib-uri&gt;<BR>&lt;taglib-location&gt;/WEB-INF/struts-logic.tld&lt;/taglib-location&gt;<BR>&lt;/taglib&gt;<BR>完成后，打开<SPAN class=style1><FONT color=#0000ff>struts-config.xml</FONT></SPAN>文件，点击这个界面左下角的<SPAN class=style1><FONT color=#0000ff>Design</FONT></SPAN>进入可视化设计界面。有没有注意右边的<SPAN class=style1><FONT color=#0000ff>Palette</FONT></SPAN> :) 点击它，让我们来开始我们的jsp页面设计。我们先建立userLoginSuccess.jsp文件，为啥先建这一个呢？等下就知道了，在myeclipse中可以一次性把我们的Action,ActionForm,Jsp文件一次建好（将三个有关联的文件等下创建）。<BR>点击<SPAN class=style1><FONT color=#0000ff>Palette</FONT></SPAN>面版上的创建JSP文件图标,弹出创建JSP文件面板。图4：<BR><IMG height=404 alt=o_4.JPG src="http://www.blogjava.net/images/blogjava_net/hexuzhong/2034/o_4.JPG" width=525 border=0><BR>
<TABLE width="100%" border=0>
<TBODY>
<TR>
<TD>
<P>在<SPAN class=style1><FONT color=#0000ff>File Name</FONT></SPAN>里输入userLoginSuccess.jsp，<SPAN class=style1><FONT color=#0000ff>Template to use</FONT></SPAN>选择2] Standard JSP using Struts 1.1,点击Finish完成。<BR>完成后，struts-config.xml文件自动被更新，可视化界在上也出现了刚新建的JSP模块。新建的jsp文件也被打开了。<BR>覆盖所有的&lt;%@ taglib ...... 为我们开始在/WEB-INF/web.xml中定义的：</P>
<P>&lt;%@ taglib uri="/tags/struts-html" prefix="html"%&gt;<BR>&lt;%@ taglib uri="/tags/struts-bean" prefix="bean"%&gt;<BR>&lt;%@ taglib uri="/tags/struts-logic" prefix="logic"%&gt; <BR><BR>然后在&lt;body&gt;&lt;/body&gt;中添加:<BR>Hello &lt;bean:write name="userName" scope="request" /&gt; .<BR>这里将request中的属性userName输出在页面上，所以等下我们在UserLoginAction中，登录成功后要设置一个相关属性。</P></TD></TR>
<TR>
<TD>
<P>OK,下面来开始我们最后三个文件的设计吧。在<SPAN class=style1><FONT color=#0000ff>Struts-config.xml</FONT></SPAN>的<SPAN class=style1><FONT color=#0000ff>Design</FONT></SPAN>模式中，在画版的空白区域点右键，选择<SPAN class=style1><FONT color=#0000ff>New</FONT></SPAN> --&gt; New <SPAN class=style1><FONT color=#0000ff>Form, Action and JSP</FONT></SPAN> 弹出ActionForm的选项面板，我们按图上输入相关值，图5：<BR><IMG height=606 alt=o_5.JPG src="http://www.blogjava.net/images/blogjava_net/hexuzhong/2034/o_5.JPG" width=615 border=0></P></TD></TR></TBODY></TABLE></P>在<SPAN class=style1><FONT color=#0000ff>Optional Details</FONT></SPAN>的<SPAN class=style1><FONT color=#0000ff>Form Properties</FONT></SPAN>选项卡，点<SPAN class=style1><FONT color=#0000ff>add</FONT></SPAN>为这个ActionForm添加相关值，在这个登录示例中，将添加两个属性userName和password，图6：<BR><IMG height=212 alt=o_6.JPG src="http://www.blogjava.net/images/blogjava_net/hexuzhong/2034/o_6.JPG" width=394 border=0><BR>在添加password时，注意将<SPAN class=style1><FONT color=#0000ff>JSP input type</FONT></SPAN> 下拉框选择password. <BR>完成这步后，我们就将ActionForm设计完成。<BR>接下来选择 <SPAN class=style1><FONT color=#0000ff>Optional Details</FONT></SPAN>的<SPAN class=style1><FONT color=#0000ff>JSP</FONT></SPAN>选项卡,我们选中<SPAN class=style1><FONT color=#0000ff>Create JSP form?</FONT></SPAN> 这一步myeclipse将为我们创建一个简单的与用户交互的登录页面。保持内容和图7一样。图7：<BR><IMG height=153 alt=o_7.JPG src="http://www.blogjava.net/images/blogjava_net/hexuzhong/2034/o_7.JPG" width=579 border=0><BR>因为我们这只是简单的演示一个登录片段，所以不用验证用户信息是否合法，所以将 <SPAN class=style1><FONT color=#0000ff>Option Details</FONT></SPAN>的<SPAN class=style1><FONT color=#0000ff>method</FONT></SPAN>选项卡的新建方法去掉，如图8：<BR><IMG height=153 alt=o_8.JPG src="http://www.blogjava.net/images/blogjava_net/hexuzhong/2034/o_8.JPG" width=579 border=0><BR>点Next，进入Action选项面板.将<SPAN class=style1><FONT color=#0000ff>Option Details</FONT></SPAN>的<SPAN class=style1><FONT color=#0000ff>Form</FONT></SPAN>选项卡中<SPAN class=style1><FONT color=#0000ff>Validate Form</FONT></SPAN>取消选择，如图9：<BR><IMG height=606 alt=o_9.JPG src="http://www.blogjava.net/images/blogjava_net/hexuzhong/2034/o_9.JPG" width=615 border=0><BR>然后在<SPAN class=style1><FONT color=#0000ff>Forwards</FONT></SPAN>选项卡中点<SPAN class=style1><FONT color=#0000ff>add</FONT></SPAN>添加成功和失败返回的页面.如图10：<BR><IMG height=172 alt=o_10.JPG src="http://www.blogjava.net/images/blogjava_net/hexuzhong/2034/o_10.JPG" width=587 border=0><BR>点击Finish完成。在<SPAN class=style1><FONT color=#0000ff>Struts-config.xml</FONT></SPAN>的<SPAN class=style1><FONT color=#0000ff>Design</FONT></SPAN>中，可以看到图11所示：<BR><IMG height=491 alt=o_11.JPG src="http://www.blogjava.net/images/blogjava_net/hexuzhong/2034/o_11.JPG" width=670 border=0><BR>最后，简单的修改一下userLogin.jsp,将所有&lt;%@ taglib ...%&gt;替换为：<BR>&lt;%@ taglib uri="/tags/struts-html" prefix="html"%&gt;<BR>&lt;%@ taglib uri="/tags/struts-bean" prefix="bean"%&gt;<BR>修改UserLoginAction中的execute片段为如下所示，图12：<BR><IMG height=334 alt=o_12.JPG src="http://www.blogjava.net/images/blogjava_net/hexuzhong/2034/o_12.JPG" width=701 border=0><BR><BR>
<TABLE width="100%" border=0>
<TBODY>
<TR>
<TD>
<P>OK，完成。。。下面就部暑项目，测试。。。</P></TD></TR>
<TR>
<TD>像为项目添加Struts框架一样，在项目名上右击，选择<SPAN class=style1><FONT color=#0000ff>MyEclipse</FONT></SPAN> --&gt; <SPAN class=style1><FONT color=#0000ff>Add and Remove Project development</FONT></SPAN>.<BR>在弹出对话框上，单击<SPAN class=style1><FONT color=#0000ff>add</FONT></SPAN> ，在弹出的 <SPAN class=style1><FONT color=#0000ff>New Deployment</FONT></SPAN> 对话框上，<SPAN class=style1><FONT color=#0000ff>Server</FONT></SPAN>选Tomcat5，点击Finish完成部署，如图13:<BR><IMG height=436 alt=o_13.JPG src="http://www.blogjava.net/images/blogjava_net/hexuzhong/2034/o_13.JPG" width=525 border=0><BR>
<TABLE width="100%" border=0>
<TBODY>
<TR>
<TD>在用浏览器上打开：http://127.0.0.1:8080/LoginDemo/userLogin.jsp</TD></TR>
<TR>
<TD>输入密码123456,用户名EricHe。显示成功：<BR></TD></TR></TBODY></TABLE><IMG height=270 alt=o_14.JPG src="http://www.blogjava.net/images/blogjava_net/hexuzhong/2034/o_14.JPG" width=342 border=0><BR>
<TABLE width="100%" border=0>
<TBODY>
<TR>
<TD>如果输错，或不输入，则无反映又回到当前登录页面（因为我们没有设置错误信息）。<BR></TD></TR>
<TR>
<TD>55555~~~ 终于写完了。。。。。。。2005-07-06</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><img src ="http://www.blogjava.net/hexuzhong/aggbug/7218.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hexuzhong/" target="_blank">HexUzHoNG</a> 2005-07-06 18:09 <a href="http://www.blogjava.net/hexuzhong/archive/2005/07/06/7218.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>