﻿<?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-阿姆斯壮 &lt;small&gt;amsz&lt;/small&gt;</title><link>http://www.blogjava.net/pepsixp/</link><description>I am strong, I am in Suzhou.</description><language>zh-cn</language><lastBuildDate>Thu, 14 May 2026 09:28:05 GMT</lastBuildDate><pubDate>Thu, 14 May 2026 09:28:05 GMT</pubDate><ttl>60</ttl><item><title>搬家了</title><link>http://www.blogjava.net/pepsixp/archive/2007/07/06/128463.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Thu, 05 Jul 2007 16:10:00 GMT</pubDate><guid>http://www.blogjava.net/pepsixp/archive/2007/07/06/128463.html</guid><description><![CDATA[走了，新的坑：<a href="http://amsz.yo2.cn/">http://amsz.yo2.cn/</a>&nbsp; 
 <img src ="http://www.blogjava.net/pepsixp/aggbug/128463.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pepsixp/" target="_blank">阿姆斯壮</a> 2007-07-06 00:10 <a href="http://www.blogjava.net/pepsixp/archive/2007/07/06/128463.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>安装 DokuWiki</title><link>http://www.blogjava.net/pepsixp/archive/2007/06/14/DokuWiki.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Thu, 14 Jun 2007 14:13:00 GMT</pubDate><guid>http://www.blogjava.net/pepsixp/archive/2007/06/14/DokuWiki.html</guid><wfw:comment>http://www.blogjava.net/pepsixp/comments/124370.html</wfw:comment><comments>http://www.blogjava.net/pepsixp/archive/2007/06/14/DokuWiki.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pepsixp/comments/commentRss/124370.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pepsixp/services/trackbacks/124370.html</trackback:ping><description><![CDATA[<p>环境：Linux AS4、Apache2.2、PHP 4.4.7、DokuWiki-2007-05-24</p>
<p>Apache的安装见<a href="http://www.blogjava.net/pepsixp/archive/2006/12/04/85237.html" target=_blank>前文</a></p>
<p><strong>PHP</strong></p>
<ol>
    <li>下载php-4.4.7.tar.gz，解压
    <li>./configure --with-apxs2=$APACHE_HOME/bin/apxs
    <li>make &amp; make install
    <li>cp php.ini-dist&nbsp;&amp;PHP_HOME/etc/php.ini </li>
</ol>
<p><strong>DokuWiki</strong></p>
<ol>
    <li>下载dokuwiki-2006-11-06.tgz，解压
    <li>为apache添加rewrite模块：<br>cd $APACHE_HOME/modules/mappers<br>$APACHE_HOME/bin/apxs -i -a -c mod_rewrite.c
    <li>检查httpd.conf中是否已经加入：LoadModule rewrite_module libexec/mod_rewrite.so
    <li>配置apache的httpd.conf<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"><span style="COLOR: #000000">Alias&nbsp;/wiki&nbsp;"/local/xsun/servers/dokuwiki"<br></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">Directory&nbsp;</span>"$DokuWiki_HOME"<span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>Allow&nbsp;from&nbsp;all&nbsp;<br><br>AddType&nbsp;application/x-httpd-php&nbsp;.php&nbsp;.phtml<br>AddType&nbsp;application/x-httpd-php-source&nbsp;.phps<br>RewriteEngine&nbsp;on<br><br>RewriteBase&nbsp;/wiki<br><br>RewriteRule&nbsp;^_media/(.*)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lib/exe/fetch.php?media=$1&nbsp;&nbsp;[QSA,L]<br>RewriteRule&nbsp;^_detail/(.*)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lib/exe/detail.php?media=$1&nbsp;&nbsp;[QSA,L]<br>RewriteRule&nbsp;^_export/([^/]+)/(.*)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doku.php?do=export_$1</span>&amp;id<span style="COLOR: #000000">=$2&nbsp;&nbsp;[QSA,L]<br>RewriteRule&nbsp;^$&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doku.php&nbsp;&nbsp;[L]<br>RewriteCond&nbsp;%{REQUEST_FILENAME}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;!-f<br>RewriteCond&nbsp;%{REQUEST_FILENAME}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;!-d<br>RewriteRule&nbsp;(.*)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doku.php?id=$1&nbsp;&nbsp;[QSA,L]<br>RewriteRule&nbsp;^index.php$&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doku.php<br>php_value&nbsp;auto_prepend_file&nbsp;"$DokuWiki_HOME/prepend.php"<br></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">Directory</span><span style="COLOR: #0000ff">&gt;</span></div>
    <li>$APACHE_HOME/bin/apachectl start </li>
</ol>
<p><strong>DokuWiki 安全配置</strong></p>
在$DokuWiki_HOME目录下创建prepend.php，和apache的配置文件对应，在执行会预先加载
<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"><span style="COLOR: #000000">&lt;?</span><span style="COLOR: #000000">php<br></span><span style="COLOR: #008080">define</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">DOKU_CONF</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">$DokuWiki_HOME/conf/</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">define</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">DOKU_INC</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000"><span style="COLOR: #000000">$DokuWiki_HOME</span></span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #000000">?&gt;</span></div>
<br>然后将$DokuWiki_HOME目录下的文件夹都移出，例如$Wiki_HOME<br>ln -s $DokuWiki_HOME/lib $Wiki_HOME/lib<br>在$DokuWiki_HOME/conf/local.php文件中添加：$conf['savedir'] = '$Wiki_HOME/data';<br>在浏览器中打开install.php，配置完后将这个文件删除<br><br>下面是我配置过的文件：<br>local.php:<br>$conf['title'] = 'My Wiki';<br>$conf['useacl'] = 1;<br>$conf['superuser'] = '@admin';<br>$conf['userewrite'] = '1';<br>$conf['useslash'] = 1;<br>$conf['sepchar'] = '-';<br>$conf['openregister'] = '0';
<p>&nbsp;$conf['savedir'] = '/local/xsun/wiki/data';<br>@include(DOKU_CONF.'local.protected.php');<br><br>users.auth.php:<br>test:61e7250f72098cf2602541ffbaf66e59:LALALA:pepsixp@gmail.com:admin,user<br><br>acl.auth.php:<br>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @ALL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @user&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8</p>
<img src ="http://www.blogjava.net/pepsixp/aggbug/124370.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pepsixp/" target="_blank">阿姆斯壮</a> 2007-06-14 22:13 <a href="http://www.blogjava.net/pepsixp/archive/2007/06/14/DokuWiki.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PEPSIXP</title><link>http://www.blogjava.net/pepsixp/archive/2007/06/13/123739.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Tue, 12 Jun 2007 16:08:00 GMT</pubDate><guid>http://www.blogjava.net/pepsixp/archive/2007/06/13/123739.html</guid><wfw:comment>http://www.blogjava.net/pepsixp/comments/123739.html</wfw:comment><comments>http://www.blogjava.net/pepsixp/archive/2007/06/13/123739.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pepsixp/comments/commentRss/123739.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pepsixp/services/trackbacks/123739.html</trackback:ping><description><![CDATA[<p>PEPSIXP = PEPSI + XP = 百事可乐 + 极限编程 = 一个爱喝百事可乐，向往加入敏捷团队的程序员<br>冰云的<a href="http://blog.nona.name/200704244.html" target=_blank>敏捷团队建设</a>看得我心直痒痒，貌似看到了一个程序员的天堂。有的团队成天忙忙碌碌，进度缓慢Bug大堆还浪费了自己大好的年华；有的团队嘻嘻哈哈，却有着极高的工作效率，这就是环境带来的差异。<br><br>女怕嫁错郎，男怕入错行，老话没错的！写在公司又一同志离职当天晚上。</p>
<img src ="http://www.blogjava.net/pepsixp/aggbug/123739.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pepsixp/" target="_blank">阿姆斯壮</a> 2007-06-13 00:08 <a href="http://www.blogjava.net/pepsixp/archive/2007/06/13/123739.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>IDEA 6与Junit 4 版本不兼容</title><link>http://www.blogjava.net/pepsixp/archive/2007/04/04/108428.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Wed, 04 Apr 2007 06:43:00 GMT</pubDate><guid>http://www.blogjava.net/pepsixp/archive/2007/04/04/108428.html</guid><wfw:comment>http://www.blogjava.net/pepsixp/comments/108428.html</wfw:comment><comments>http://www.blogjava.net/pepsixp/archive/2007/04/04/108428.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/pepsixp/comments/commentRss/108428.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pepsixp/services/trackbacks/108428.html</trackback:ping><description><![CDATA[IDEA 6.0.4 不能跑Junit4.2 - <a href="http://www.jetbrains.net/jira/browse/IDEA-12183" target=_blank>ISSUES<br></a>IDEA 6.0.5 不能跑Junit4.3 - <a href="http://www.jetbrains.net/jira/browse/IDEADEV-13294" target=_blank>ISSUES</a><br><br>Intellij IDEA总是慢一拍，所以最高版本的配置就是：IDEA 6.0.5 + Junit4.2
<img src ="http://www.blogjava.net/pepsixp/aggbug/108428.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pepsixp/" target="_blank">阿姆斯壮</a> 2007-04-04 14:43 <a href="http://www.blogjava.net/pepsixp/archive/2007/04/04/108428.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Hibernate OneToOne 复合主键</title><link>http://www.blogjava.net/pepsixp/archive/2007/02/01/97387.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Thu, 01 Feb 2007 15:55:00 GMT</pubDate><guid>http://www.blogjava.net/pepsixp/archive/2007/02/01/97387.html</guid><wfw:comment>http://www.blogjava.net/pepsixp/comments/97387.html</wfw:comment><comments>http://www.blogjava.net/pepsixp/archive/2007/02/01/97387.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pepsixp/comments/commentRss/97387.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pepsixp/services/trackbacks/97387.html</trackback:ping><description><![CDATA[
		<p>主表有两个字段映射到副表，可以取得唯一记录，但这条记录不定存在，这两个字段需要做条件过滤，就这个状况。</p>
		<p>Hibernate Annotation 配置的注意点：</p>
		<ul>
				<li>需要映射字段的@Column属性设为insertable = false, updatable = false，</li>
				<ul>
						<li>不产生列重复的异常 
</li>
						<li>在hql解析的时候，自动合并相同的列(<a href="http://java-aap.blogspot.com/2006/04/hibernate-annotations-composite.html" target="_blank">参考</a>) </li>
				</ul>
				<li>类必须implements Serializable，不然会抛ClassCaseException(郁闷4个小时 -_-!) </li>
		</ul>
		<strong>HQL</strong>
		<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">select</span>
				<span style="COLOR: #000000"> s</span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000">ScopeProjection s </span>
				<span style="COLOR: #ff00ff">left</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">join</span> <span style="COLOR: #0000ff">fetch</span><span style="COLOR: #000000"> s.override</span><span style="COLOR: #0000ff">where</span><span style="COLOR: #000000"> s.hubsite</span><span style="COLOR: #808080">=</span><span style="COLOR: #000000">? </span><span style="COLOR: #808080">and</span><span style="COLOR: #000000">s.companyabbr</span><span style="COLOR: #808080">=</span><span style="COLOR: #000000">?</span></div>
		<br />
		<strong>CODE</strong>
		<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">
				<span style="COLOR: #000000">@Entity<br />@SequenceGenerator(name</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">SEQ_GEN</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">, sequenceName</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">SCOPEPROJECTIONSEQ</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">)<br /></span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> ScopeProjection </span>
				<span style="COLOR: #0000ff">implements</span>
				<span style="COLOR: #000000"> Serializable {<br />    </span>
				<span style="COLOR: #0000ff">private</span>
				<span style="COLOR: #000000"> Integer id;<br />    </span>
				<span style="COLOR: #0000ff">private</span>
				<span style="COLOR: #000000"> String hubsite;<br />    </span>
				<span style="COLOR: #0000ff">private</span>
				<span style="COLOR: #000000"> String companyabbr;<br />    </span>
				<span style="COLOR: #0000ff">private</span>
				<span style="COLOR: #000000"> ScopeProjectionOverride override;<br /><br />    @Id<br />    @Column(name </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">PROJECTIONID</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">)<br />    @GeneratedValue(strategy </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> GenerationType.AUTO, generator </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">SEQ_GEN</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">)<br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> Integer getId() {<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> id;<br />    }<br /><br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> setId(Integer id) {<br />        </span>
				<span style="COLOR: #0000ff">this</span>
				<span style="COLOR: #000000">.id </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> id;<br />    }<br /><br />    @Column(name </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">HUBSITENAME</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">, nullable </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">false</span>
				<span style="COLOR: #000000">, insertable </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">false</span>
				<span style="COLOR: #000000">, updatable </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">false</span>
				<span style="COLOR: #000000">)<br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> String getHubsite() {<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> hubsite;<br />    }<br /><br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> setHubsite(String hubsite) {<br />        </span>
				<span style="COLOR: #0000ff">this</span>
				<span style="COLOR: #000000">.hubsite </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> hubsite;<br />    }<br /><br />    @Column(name </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">COMPANYABBREVIATION</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">, nullable </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">false</span>
				<span style="COLOR: #000000">, insertable </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">false</span>
				<span style="COLOR: #000000">, updatable </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">false</span>
				<span style="COLOR: #000000">)<br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> String getCompanyabbr() {<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> companyabbr;<br />    }<br /><br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> setCompanyabbr(String companyabbr) {<br />        </span>
				<span style="COLOR: #0000ff">this</span>
				<span style="COLOR: #000000">.companyabbr </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> companyabbr;<br />    }<br />    <br />    @OneToOne(cascade </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> CascadeType.PERSIST)<br />    @JoinColumns ({<br />        @JoinColumn(name </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">COMPANYABBREVIATION</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">, referencedColumnName </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">COMPANYABBREVIATION</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">),<br />        @JoinColumn(name </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">HUBSITENAME</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">, referencedColumnName </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">HUBSITENAME</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">)<br />    })<br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> ScopeProjectionOverride getOverride() {<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> override;<br />    }<br /><br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> setOverride(ScopeProjectionOverride override) {<br />        </span>
				<span style="COLOR: #0000ff">this</span>
				<span style="COLOR: #000000">.override </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> override;<br />    }<br />}</span>
		</div>
		<br />
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #000000">@Entity<br />@SequenceGenerator(name</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">SEQ_GEN</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">, sequenceName</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">SCOPEOVERRIDESEQ</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">)<br /></span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> ScopeProjectionOverride </span>
				<span style="COLOR: #0000ff">implements</span>
				<span style="COLOR: #000000"> Serializable {<br />    </span>
				<span style="COLOR: #0000ff">private</span>
				<span style="COLOR: #000000"> Integer id;<br />    </span>
				<span style="COLOR: #0000ff">private</span>
				<span style="COLOR: #000000"> String companyabbr;<br />    </span>
				<span style="COLOR: #0000ff">private</span>
				<span style="COLOR: #000000"> String hubsitename;<br /><br />    @Id<br />    @Column(name </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">OVERRIDEID</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">)<br />    @GeneratedValue(strategy </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> GenerationType.AUTO, generator </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">SEQ_GEN</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">)<br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> Integer getId() {<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> id;<br />    }<br /><br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> setId(Integer id) {<br />        </span>
				<span style="COLOR: #0000ff">this</span>
				<span style="COLOR: #000000">.id </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> id;<br />    }<br /><br />    @Column(name </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">COMPANYABBREVIATION</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">)<br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> String getCompanyabbr() {<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> companyabbr;<br />    }<br /><br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> setCompanyabbr(String companyabbr) {<br />        </span>
				<span style="COLOR: #0000ff">this</span>
				<span style="COLOR: #000000">.companyabbr </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> companyabbr;<br />    }<br /><br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> String getHubsitename() {<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> hubsitename;<br />    }<br /><br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> setHubsitename(String hubsitename) {<br />        </span>
				<span style="COLOR: #0000ff">this</span>
				<span style="COLOR: #000000">.hubsitename </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> hubsitename;<br />    }<br />}</span>
		</div>
<img src ="http://www.blogjava.net/pepsixp/aggbug/97387.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pepsixp/" target="_blank">阿姆斯壮</a> 2007-02-01 23:55 <a href="http://www.blogjava.net/pepsixp/archive/2007/02/01/97387.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SVN 配置</title><link>http://www.blogjava.net/pepsixp/archive/2006/12/21/89268.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Thu, 21 Dec 2006 05:38:00 GMT</pubDate><guid>http://www.blogjava.net/pepsixp/archive/2006/12/21/89268.html</guid><wfw:comment>http://www.blogjava.net/pepsixp/comments/89268.html</wfw:comment><comments>http://www.blogjava.net/pepsixp/archive/2006/12/21/89268.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pepsixp/comments/commentRss/89268.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pepsixp/services/trackbacks/89268.html</trackback:ping><description><![CDATA[
		<h3>创建</h3>
		<ol>
				<li>mkdir /etc/svn/repos1 
</li>
				<li>svnadmin create /etc/svn/repos1 
</li>
				<li>svn import file:///etc/svn/repos1  --message "init" // 导入当前目录下所以文件<br />svn import /local/mydir/ file:///etc/svn/repos1  --message "init" // 导入指定目录下所以文件 </li>
		</ol>
		<h3>查看</h3>
		<ul>
				<li>svn list --verbose file:///etc/svn/repos1/ 
</li>
				<li>svnlook info /etc/svn/repos1/ 
</li>
				<li>svnlook tree /etc/svn/repos1/ --show-ids </li>
		</ul>
		<h3>Apache权限控制</h3>${apache}/conf/httpd.conf 的配置：<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">LoadModule dav_svn_module     modules</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">mod_dav_svn</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">so<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />LoadModule authz_svn_module   modules</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">mod_authz_svn</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">so<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">Location </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">svn</span><span style="COLOR: #000000">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />DAV svn<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />SVNParentPath </span><span style="COLOR: #000000"><span style="COLOR: #000000">/</span><span style="COLOR: #0000ff">etc</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">svn</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">repos1</span></span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />SVNListParentPath on<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" />AuthType Basic<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />AuthName </span><span style="FONT-WEIGHT: bold; COLOR: #000000">"</span><span style="FONT-WEIGHT: bold; COLOR: #000000">MY SVN Repository</span><span style="FONT-WEIGHT: bold; COLOR: #000000">"</span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />AuthUserFile </span><span style="COLOR: #000000"><span style="COLOR: #000000">/</span><span style="COLOR: #0000ff">etc</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">svn</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">repos1</span></span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">passwd</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">conf<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />AuthzSVNAccessFile </span><span style="COLOR: #000000">/</span><span style="COLOR: #0000ff">etc</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">svn</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">repos1</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">authz</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">conf<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">Require</span><span style="COLOR: #000000"> vaild</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">user<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">&lt;/</span><span style="COLOR: #000000">Location</span><span style="COLOR: #000000">&gt;</span></div><br />创建用户和密码：${apache}/bin/htpasswd /etc/svn/repos1/authz.comf user1<br /><br />authz.conf的配置：<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">[groups]<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />group1 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> user1<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />group2 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> user1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">user2<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" />[</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">]<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> r<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" />[project1</span><span style="COLOR: #000000">:/</span><span style="COLOR: #000000">path1]<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #800080">@group1</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> rw<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" />[project1</span><span style="COLOR: #000000">:/</span><span style="COLOR: #000000">path2]<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #800080">@group2</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> rw</span></div><br /><p>取出：svn co file:///etc/svn/report1</p><p>另外需要修改两个地方，不然无法提交修改的文件：</p><ol><li>chown -R sysuser:sysuser /etc/svn/report1<br />chmod -R 700 /etc/svn/report1
</li><li>在${apache}/conf/httpd.conf中找到：<br />User daemon<br />Group daemon<br />改为<br />User sysuser<br />Group sysuser<br />以root用户启动apache后，自动切换到sysuser身份运行</li></ol><img src ="http://www.blogjava.net/pepsixp/aggbug/89268.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pepsixp/" target="_blank">阿姆斯壮</a> 2006-12-21 13:38 <a href="http://www.blogjava.net/pepsixp/archive/2006/12/21/89268.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Apache + Subversion 安装</title><link>http://www.blogjava.net/pepsixp/archive/2006/12/04/85237.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Mon, 04 Dec 2006 05:16:00 GMT</pubDate><guid>http://www.blogjava.net/pepsixp/archive/2006/12/04/85237.html</guid><wfw:comment>http://www.blogjava.net/pepsixp/comments/85237.html</wfw:comment><comments>http://www.blogjava.net/pepsixp/archive/2006/12/04/85237.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pepsixp/comments/commentRss/85237.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pepsixp/services/trackbacks/85237.html</trackback:ping><description><![CDATA[
		<p>环境：SunOS 5.9 Generic、Apache-2.2.3、Subversion-1.4.2</p>
		<p>
				<strong>Apache</strong>
		</p>
		<ol>
				<li>下载httpd-2.2.3.tar.gz，解压 
</li>
				<li>检查path是否加入了：/usr/ccs/bin，这是我make报错的根源，之后就一马平川了 
</li>
				<li>$ ./configure --enable-dav --enable-so --prefix=/usr/local/apache2/ 
</li>
				<li>$ make;make install 
</li>
				<li>修改/usr/local/apache2/conf/httpd.conf中的ServerName的配置，写上服务器的IP地址和端口号，例如ServerName  12.34.56.78:80 
</li>
				<li>进入bin目录启动(需要root)，# ./apachectl start 
</li>
				<li>打开浏览器<a href="http://ip_address/">http://ip_address/</a>，等待测试页"It works!"的出现 :_) </li>
		</ol>
		<p>
				<strong>Subversion</strong>
		</p>
		<ol>
				<li>下载neon-0.26.2.tar.gz，解压 
</li>
				<li>$ ./configure --prefix=/usr/local/neon; make; make install 
</li>
				<li>下载subversion-1.4.2.tar.gz，解压 
</li>
				<li>$ ./configure --prefix=/usr/local/subversion --with-apxs=/usr/local/apache2/bin/apxs --with-apr=/usr/local/apache2 --with-apr-util=/usr/local/apache2 --with-neon=/usr/local/neon --with-ssl --with-zlib 
</li>
				<li>$ make;make install 
</li>
				<li>修改apache配置文件httpd.conf：<br />LoadModule dav_svn_module modules/mod_dav_svn.so <br />LoadModule authz_svn_module modules/mod_authz_svn.so <br />&lt;Location /svn&gt;<br />DAV svn <br />SVNParentPath /home/svnroot/<br />&lt;/Location&gt; 
</li>
				<li>创建仓库：<br />$ mkdir /home/svnroot/<br />$ cd /usr/local/subversion/bin<br />$ ./svnadmin create /home/svnroot/test<br />$ ./svn import /home/user/import <a href="file:///home/svnroot/test">file:///home/svnroot/test</a> –m "import files test" 
</li>
				<li>重启Apache<br />$ ./usr/local/apache2/bin/apachectl restart<br />打开浏览器：http://localhost/svn/test ，应该能看到些什么东西 </li>
		</ol>
<img src ="http://www.blogjava.net/pepsixp/aggbug/85237.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pepsixp/" target="_blank">阿姆斯壮</a> 2006-12-04 13:16 <a href="http://www.blogjava.net/pepsixp/archive/2006/12/04/85237.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ubuntu6.10 - 初始化</title><link>http://www.blogjava.net/pepsixp/archive/2006/11/12/80654.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Sat, 11 Nov 2006 16:52:00 GMT</pubDate><guid>http://www.blogjava.net/pepsixp/archive/2006/11/12/80654.html</guid><wfw:comment>http://www.blogjava.net/pepsixp/comments/80654.html</wfw:comment><comments>http://www.blogjava.net/pepsixp/archive/2006/11/12/80654.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pepsixp/comments/commentRss/80654.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pepsixp/services/trackbacks/80654.html</trackback:ping><description><![CDATA[升级了一下ubuntu，记录一下<br /><ol><li>激活root用户：<br />
sudo passwd root</li><li>修改源：<br />
sudo gedit /etc/apt/sources.list<br />删除所有内容并添加如下信息(江苏省常州市电信)：<br />deb http://ubuntu.cn99.com/ubuntu/ edgy main restricted universe multiverse<br />deb http://ubuntu.cn99.com/ubuntu/ edgy-security main restricted universe multiverse<br />deb http://ubuntu.cn99.com/ubuntu/ edgy-updates main restricted universe multiverse<br />deb http://ubuntu.cn99.com/ubuntu/ edgy-proposed main restricted universe multiverse<br />deb http://ubuntu.cn99.com/ubuntu/ edgy-backports main restricted universe multiverse<br />deb http://ubuntu.cn99.com/ubuntu-cn/ edgy main restricted universe multiverse</li><li>升级系统：<br />sudo apt-get update<br />
sudo apt-get dist-upgrade</li><li>设置本地local环境：<br />sudo dpkg-reconfigure locales</li><li>安装中文语言支持:<br />do apt-get install language-pack-gnome-zh language-pack-gnome-zh-base language-pack-zh language-pack-zh-base language-support-zh<br /></li><li>
安装中文字体：<br />sudo apt-get install ttf-arphic-ukai ttf-arphic-uming</li><li>安装编译环境:<br />
sudo apt-get install build-essential</li><li>更改 GRUB 菜单内开机系统的预设值<br />sudo vi /boot/grub/menu.lst<br />修改 ... default 0 ...<br /></li></ol>好了，注销一下电脑，再次登入后按 Ctrl + 空格键(激活输入法) 应该可以使用，并且整个界面都是中文的了。<img src ="http://www.blogjava.net/pepsixp/aggbug/80654.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pepsixp/" target="_blank">阿姆斯壮</a> 2006-11-12 00:52 <a href="http://www.blogjava.net/pepsixp/archive/2006/11/12/80654.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用DbUnit</title><link>http://www.blogjava.net/pepsixp/archive/2005/09/05/12124.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Mon, 05 Sep 2005 15:05:00 GMT</pubDate><guid>http://www.blogjava.net/pepsixp/archive/2005/09/05/12124.html</guid><wfw:comment>http://www.blogjava.net/pepsixp/comments/12124.html</wfw:comment><comments>http://www.blogjava.net/pepsixp/archive/2005/09/05/12124.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pepsixp/comments/commentRss/12124.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pepsixp/services/trackbacks/12124.html</trackback:ping><description><![CDATA[<P>当我刚开始编写和数据库有关的单元测试时，就知道这些测试代码在下次运行的时候可能无法完全通过，因为它和数据紧密的联系在一起，但也想不出一个好的解决方案。它只保证了当时的代码是没有问题的，一个星期后，不，可能在这次单元测试运行完后，就应该丢进垃圾桶了。<BR>这种吃力不讨好的行为持续了一段时间，直到引入了DbUnit之后。它确实能够的保证数据库处于一个稳定的状态，无须对其进行人工干预，操作也非常简单。<BR><BR>创建一个<STRONG>DbUnit Test Case<BR></STRONG>。。。<BR></P><img src ="http://www.blogjava.net/pepsixp/aggbug/12124.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pepsixp/" target="_blank">阿姆斯壮</a> 2005-09-05 23:05 <a href="http://www.blogjava.net/pepsixp/archive/2005/09/05/12124.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>加班结束了</title><link>http://www.blogjava.net/pepsixp/archive/2005/03/26/2492.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Sat, 26 Mar 2005 15:49:00 GMT</pubDate><guid>http://www.blogjava.net/pepsixp/archive/2005/03/26/2492.html</guid><wfw:comment>http://www.blogjava.net/pepsixp/comments/2492.html</wfw:comment><comments>http://www.blogjava.net/pepsixp/archive/2005/03/26/2492.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pepsixp/comments/commentRss/2492.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pepsixp/services/trackbacks/2492.html</trackback:ping><description><![CDATA[从上个星期五，到这个星期五，整整一个星期，每天8:30上班，22：00下班，感觉是整个人都买给公司了，回到家能做的事情就剩睡觉了。第一次这样的连续奋战，人倒是没怎么感到累，也许都习惯了吧，反正在家的时候也常常12多才睡觉的。唯一的不满就是伙食，早饭是用饼干解决的，起床发现眼睛浮肿或眼圈发黑，就再奖赏自己一袋牛奶，中午把胃买给了科技园的食堂，食堂的饭是那宁愿选择泡面也不去吃它饭的那种，但没办法，垄断经营，不吃的话，就要吃两顿泡面了，防腐剂涉入太多，人就容易麻木，晚饭光临可的，主食除了方便面，再加些没营养的豆腐干、薯片之类的零食。把身体折腾了一个星期，肚子终于忍不住反抗了，星期五的晚上咕咕直叫，星期六就跑肚拉稀的过了一个上午，看看镜子里的我，死狗一只。<BR><BR>好不容易坚持了一个星期的晨跑，被这突入其来的加班冲的不知哪边去了。不知下个星期还能不能继续坚持下去，身体啊身体啊，老了可别怪我，谁让你这么懒的。工作了一年多，现在一直感到脖子痛，白发也多了不少，背部时不时的也会产生一阵疼痛，一直怀疑是不是脊椎出了什么问题，正好那时在看《白影》，江直发病时痛苦的表情，害我恐惧了整一个星期，后来和同事的交流中才发现，是凳子的问题，他们也有这种情况发生，现在换凳子了，这个症状也没有出现了。在连续一个星期的晨跑坚持下来后，精神和身子骨出奇的爽朗，跑路脚底都觉得很轻盈，但是早上7点爬起来，对我来说太有难度了，这可比加一个星期的班难多了。想想现在这种用身体换金钱的方式，和民工有什么区别，可能连民工都不如吧。什么事情都贵在坚持，晨跑是这样，工作也是这样。<BR><BR>研究生很厉害，不见得，只能说是良莠不齐！这次加了这么多的班，有部分原因就是他们造成的。公司外包给他们的程序，最后由我做测试和修改，看看源代码，连最起码的变量名首字母小写都不能遵守，还指望在代码中找到一段优雅的代码以供学习吗？异常处理，日志输出，代码重用，随心所欲的做，好像完全是为了完成任务而做的，当我把代码测试并修改完后，发现有些类剩下的代码数量甚至连原来的一半都不到，哈哈，修啊修啊改啊改啊，一个星期的光阴很快就过去了，失去了一些，也得到了一些。<BR><BR>最近被《钢之炼金术士》感动不已：没有牺牲就没有获得，想要得到什么，就必须付出同等的代价，这是炼金术中的等价交换原则，也是现实中的等价交换原则！<img src ="http://www.blogjava.net/pepsixp/aggbug/2492.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pepsixp/" target="_blank">阿姆斯壮</a> 2005-03-26 23:49 <a href="http://www.blogjava.net/pepsixp/archive/2005/03/26/2492.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>学习FreeMarker（二）</title><link>http://www.blogjava.net/pepsixp/archive/2005/03/11/1941.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Fri, 11 Mar 2005 03:08:00 GMT</pubDate><guid>http://www.blogjava.net/pepsixp/archive/2005/03/11/1941.html</guid><wfw:comment>http://www.blogjava.net/pepsixp/comments/1941.html</wfw:comment><comments>http://www.blogjava.net/pepsixp/archive/2005/03/11/1941.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pepsixp/comments/commentRss/1941.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pepsixp/services/trackbacks/1941.html</trackback:ping><description><![CDATA[<P><STRONG>用户定义指令</STRONG>－使用@符合来调用<BR>有两种不同的类型：Macro(宏)和transform(传递器)，Macro是在模板中使用macro指令定义，而transform是在模板外由程序定义(基本上都是基于Java的)，这里通过Macro来介绍自定义指令。<BR>例一：<BR>&lt;#macro greet&gt;<BR>&nbsp; &lt;font size="+2"&gt;Hello Joe!&lt;/font&gt;<BR>&lt;/#macro&gt;&nbsp; <BR>使用：&lt;@greet&gt;&lt;<A>/@greet</A>&gt; 或 &lt;@greet/&gt;<BR>结果：&lt;font size="+2"&gt;Hello Joe!&lt;/font&gt;</P>
<P>参数－在macro指令中可以在宏变量之后定义参数<BR>例二：<BR>&lt;#macro greet person&gt;<BR>&nbsp; &lt;font size="+2"&gt;Hello ${person}!&lt;/font&gt;<BR>&lt;/#macro&gt; <BR>使用：&lt;@greet person="Fred"/&gt; and &lt;@greet person="Batman"/&gt; <BR>结果： &lt;font size="+2"&gt;Hello Fred!&lt;/font&gt; and &lt;font size="+2"&gt;Hello Batman!&lt;/font&gt;</P>
<P>macro可以有多个参数，参数的次序是无关的，在macro指令中只能使用定义的参数，并且必须对所有参数赋值，可以在定义参数时指定缺省值：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#macro&nbsp;</SPAN><SPAN style="COLOR: #ff0000">greet&nbsp;person&nbsp;color</SPAN><SPAN style="COLOR: #0000ff">="black"</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">font&nbsp;</SPAN><SPAN style="COLOR: #ff0000">size</SPAN><SPAN style="COLOR: #0000ff">="+2"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;color</SPAN><SPAN style="COLOR: #0000ff">="${color}"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">Hello&nbsp;${person}!</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">font</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">#macro</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV>
<P><BR><STRONG>在自定义指令嵌套内容</STRONG>：模板片断中使用&lt;#nested&gt;指令</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#macro&nbsp;</SPAN><SPAN style="COLOR: #ff0000">border</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">table&nbsp;</SPAN><SPAN style="COLOR: #ff0000">border</SPAN><SPAN style="COLOR: #0000ff">=4&nbsp;</SPAN><SPAN style="COLOR: #ff0000">cellspacing</SPAN><SPAN style="COLOR: #0000ff">=0&nbsp;</SPAN><SPAN style="COLOR: #ff0000">cellpadding</SPAN><SPAN style="COLOR: #0000ff">=4&gt;&lt;tr&gt;&lt;td&gt;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #ff0000">&lt;#nested</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">tr</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;/</SPAN><SPAN style="COLOR: #800000">td</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;/</SPAN><SPAN style="COLOR: #800000">table</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">#macro</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV></DIV>
<P>使用：&lt;@border&gt;The bordered text&lt;<A>/@border</A>&gt;<BR>结果：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">table&nbsp;</SPAN><SPAN style="COLOR: #ff0000">border</SPAN><SPAN style="COLOR: #0000ff">=4&nbsp;</SPAN><SPAN style="COLOR: #ff0000">cellspacing</SPAN><SPAN style="COLOR: #0000ff">=0&nbsp;</SPAN><SPAN style="COLOR: #ff0000">cellpadding</SPAN><SPAN style="COLOR: #0000ff">=4&gt;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #ff0000">&lt;tr</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;</SPAN><SPAN style="COLOR: #800000">td</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">The&nbsp;bordered&nbsp;text<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">tr</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;/</SPAN><SPAN style="COLOR: #800000">td</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;/</SPAN><SPAN style="COLOR: #800000">table</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV></DIV>
<P>&lt;#nested&gt;指令可以被多次调用：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#macro&nbsp;</SPAN><SPAN style="COLOR: #ff0000">do_thrice</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#nested</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#nested</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#nested</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">#macro</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV></DIV>
<P>使用：<BR>&lt;@do_thrice&gt;Anything.&lt;<A>/@do_thrice</A>&gt;&nbsp; <BR>结果：<BR>Anything.<BR>Anything.<BR>Anything. </P>
<P><STRONG>注意</STRONG>：嵌套内容是无法访问到macro中的局部变量的。<BR>例如：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#macro&nbsp;</SPAN><SPAN style="COLOR: #ff0000">repeat&nbsp;count</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#local&nbsp;</SPAN><SPAN style="COLOR: #ff0000">y&nbsp;</SPAN><SPAN style="COLOR: #0000ff">=&nbsp;"test"</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#list&nbsp;</SPAN><SPAN style="COLOR: #ff0000">1..count&nbsp;as&nbsp;x</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;${y}&nbsp;${count}/${x}:&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#nested</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">#list</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">#macro</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">@repeat&nbsp;</SPAN><SPAN style="COLOR: #ff0000">count</SPAN><SPAN style="COLOR: #0000ff">=3&gt;${y?default("?")}&nbsp;</SPAN><SPAN style="COLOR: #ff0000">${x?default("?")}&nbsp;${count?default("?")}&lt;/@repeat</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV></DIV>
<P>结果：<BR>test 3/1: ? ? ?<BR>test 3/2: ? ? ?<BR>test 3/3: ? ? ?</P>
<P><BR>下面是一个嵌套使用自定义指令的例子：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">@border</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">ul</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">@do_thrice</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">li</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;</SPAN><SPAN style="COLOR: #800000">@greet&nbsp;</SPAN><SPAN style="COLOR: #ff0000">person</SPAN><SPAN style="COLOR: #0000ff">="Joe"</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">@do_thrice</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">ul</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">@border</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN></DIV></DIV>
<P>结果：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">table&nbsp;</SPAN><SPAN style="COLOR: #ff0000">border</SPAN><SPAN style="COLOR: #0000ff">=4&nbsp;</SPAN><SPAN style="COLOR: #ff0000">cellspacing</SPAN><SPAN style="COLOR: #0000ff">=0&nbsp;</SPAN><SPAN style="COLOR: #ff0000">cellpadding</SPAN><SPAN style="COLOR: #0000ff">=4&gt;&lt;tr&gt;&lt;td&gt;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #ff0000">&lt;ul</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">li</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;</SPAN><SPAN style="COLOR: #800000">font&nbsp;</SPAN><SPAN style="COLOR: #ff0000">size</SPAN><SPAN style="COLOR: #0000ff">="+2"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">Hello&nbsp;Joe!</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">font</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">li</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;</SPAN><SPAN style="COLOR: #800000">font&nbsp;</SPAN><SPAN style="COLOR: #ff0000">size</SPAN><SPAN style="COLOR: #0000ff">="+2"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">Hello&nbsp;Joe!</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">font</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">li</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;</SPAN><SPAN style="COLOR: #800000">font&nbsp;</SPAN><SPAN style="COLOR: #ff0000">size</SPAN><SPAN style="COLOR: #0000ff">="+2"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">Hello&nbsp;Joe!</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">font</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">ul</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">tr</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;/</SPAN><SPAN style="COLOR: #800000">td</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;/</SPAN><SPAN style="COLOR: #800000">table</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;</SPAN></DIV></DIV>
<P>在macro中<STRONG>使用循环变量</STRONG>－作为nested指令的参数传递循环变量的实际值，而在调用用户定义指令时，在&lt;@…&gt;开始标记的参数后面指定循环变量的名字：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#macro&nbsp;</SPAN><SPAN style="COLOR: #ff0000">repeat&nbsp;count</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#list&nbsp;</SPAN><SPAN style="COLOR: #ff0000">1..count&nbsp;as&nbsp;x</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">#nested&nbsp;</SPAN><SPAN style="COLOR: #ff0000">x,&nbsp;x/2,&nbsp;x</SPAN><SPAN style="COLOR: #0000ff">==count&gt;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #ff0000">&lt;/#list</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">#macro</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">@repeat&nbsp;</SPAN><SPAN style="COLOR: #ff0000">count</SPAN><SPAN style="COLOR: #0000ff">=4&nbsp;</SPAN><SPAN style="COLOR: #ff0000">;&nbsp;c,&nbsp;halfc,&nbsp;last</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;${c}.&nbsp;${halfc}</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#if&nbsp;</SPAN><SPAN style="COLOR: #ff0000">last</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;Last!</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">#if</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"><A>/</SPAN><SPAN style="COLOR: #800000">@repeat</SPAN><SPAN style="COLOR: #0000ff"></A></SPAN></DIV></DIV>
<P>&nbsp;结果：<BR>1. 0.5<BR>2. 1<BR>3. 1.5<BR>4. 2 Last!</P>
<P><STRONG>注意</STRONG>：循环变量和用户定义指令开始标记指定的数目可以不同，调用时少指定循环变量，则多指定的值不可见，调用时多指定循环变量，多余的循环变量不会被创建。<BR><BR><STRONG>模板中的变量</STRONG>，有三种类型：<BR>1.) <STRONG>plain(全局)变量</STRONG>：可以在模板的任何地方访问，包括使用include指令插入的模板，使用assign指令创建和替换<BR>2.) <STRONG>局部变量</STRONG>：在macro中有效，使用local指令创建和替换<BR>3.) <STRONG>循环变量</STRONG>：只能存在于指令的嵌套内容，由指令(如list)自动创建；宏的参数是局部变量，而不是循环变量</P>
<P>用assign指令创建和替换的例子：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#assign&nbsp;</SPAN><SPAN style="COLOR: #ff0000">x&nbsp;</SPAN><SPAN style="COLOR: #0000ff">=&nbsp;1&gt;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #ff0000">&lt;#--&nbsp;create&nbsp;variable&nbsp;x&nbsp;--</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${x}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#assign&nbsp;</SPAN><SPAN style="COLOR: #ff0000">x&nbsp;</SPAN><SPAN style="COLOR: #0000ff">=&nbsp;x&nbsp;</SPAN><SPAN style="COLOR: #ff0000">+&nbsp;3</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000">replace&nbsp;variable&nbsp;x&nbsp;--</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${x}&nbsp;&nbsp;</SPAN></DIV></DIV>
<P>结果：<BR>1<BR>4</P>
<P>局部变量隐藏(而不是覆盖)同名的plain变量；循环变量隐藏同名的局部变量和plain变量，下面是一个例子：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#assign&nbsp;</SPAN><SPAN style="COLOR: #ff0000">x&nbsp;</SPAN><SPAN style="COLOR: #0000ff">=&nbsp;"plain"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>1.&nbsp;${x}&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000">we&nbsp;see&nbsp;the&nbsp;plain&nbsp;var.&nbsp;here&nbsp;--</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">@test</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>6.&nbsp;${x}&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000">the&nbsp;value&nbsp;of&nbsp;plain&nbsp;var.&nbsp;was&nbsp;not&nbsp;changed&nbsp;--</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">#list&nbsp;</SPAN><SPAN style="COLOR: #ff0000">["loop"]&nbsp;as&nbsp;x</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;7.&nbsp;${x}&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000">now&nbsp;the&nbsp;loop&nbsp;var.&nbsp;hides&nbsp;the&nbsp;plain&nbsp;var.&nbsp;--</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">#assign&nbsp;</SPAN><SPAN style="COLOR: #ff0000">x&nbsp;</SPAN><SPAN style="COLOR: #0000ff">=&nbsp;"plain2"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000">replace&nbsp;the&nbsp;plain&nbsp;var,&nbsp;hiding&nbsp;does&nbsp;not&nbsp;mater&nbsp;here&nbsp;--</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;8.&nbsp;${x}&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000">it&nbsp;still&nbsp;hides&nbsp;the&nbsp;plain&nbsp;var.&nbsp;--</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">#list</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>9.&nbsp;${x}&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000">the&nbsp;new&nbsp;value&nbsp;of&nbsp;plain&nbsp;var.&nbsp;--</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;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#macro&nbsp;</SPAN><SPAN style="COLOR: #ff0000">test</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;2.&nbsp;${x}&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000">we&nbsp;still&nbsp;see&nbsp;the&nbsp;plain&nbsp;var.&nbsp;here&nbsp;--</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#local&nbsp;</SPAN><SPAN style="COLOR: #ff0000">x&nbsp;</SPAN><SPAN style="COLOR: #0000ff">=&nbsp;"local"</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;3.&nbsp;${x}&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000">now&nbsp;the&nbsp;local&nbsp;var.&nbsp;hides&nbsp;it&nbsp;--</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#list&nbsp;</SPAN><SPAN style="COLOR: #ff0000">["loop"]&nbsp;as&nbsp;x</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;4.&nbsp;${x}&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000">now&nbsp;the&nbsp;loop&nbsp;var.&nbsp;hides&nbsp;the&nbsp;local&nbsp;var.&nbsp;--</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">#list</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;5.&nbsp;${x}&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000">now&nbsp;we&nbsp;see&nbsp;the&nbsp;local&nbsp;var.&nbsp;again&nbsp;--</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">#macro</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;</SPAN></DIV></DIV>
<P>结果：<BR>1. plain<BR>&nbsp; 2. plain<BR>&nbsp; 3. local<BR>&nbsp;&nbsp;&nbsp; 4. loop<BR>&nbsp; 5. local<BR>6. plain<BR>&nbsp;&nbsp;&nbsp; 7. loop<BR>&nbsp;&nbsp;&nbsp; 8. loop<BR>9. plain2</P>
<P>内部循环变量隐藏同名的外部循环变量，例如：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#list&nbsp;</SPAN><SPAN style="COLOR: #ff0000">["loop&nbsp;1"]&nbsp;as&nbsp;x</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;${x}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#list&nbsp;</SPAN><SPAN style="COLOR: #ff0000">["loop&nbsp;2"]&nbsp;as&nbsp;x</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;${x}<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">#list&nbsp;</SPAN><SPAN style="COLOR: #ff0000">["loop&nbsp;3"]&nbsp;as&nbsp;x</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;${x}<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">#list</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;${x}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">#list</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;${x}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">#list</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV></DIV>
<P>结果：<BR>loop 1<BR>&nbsp;&nbsp;&nbsp; loop 2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; loop 3<BR>&nbsp;&nbsp;&nbsp; loop 2<BR>&nbsp; loop 1 </P>
<P>模板中的变量会隐藏（而不是覆盖）数据模型中同名变量，如果需要访问数据模型中的同名变量，使用特殊变量global，下面的例子假设数据模型中的user的值是Big Joe：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#assign&nbsp;</SPAN><SPAN style="COLOR: #ff0000">user&nbsp;</SPAN><SPAN style="COLOR: #0000ff">=&nbsp;"Joe&nbsp;Hider"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${user}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000">prints:&nbsp;Joe&nbsp;Hider&nbsp;--</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${.globals.user}&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000">prints:&nbsp;Big&nbsp;Joe&nbsp;--</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;</SPAN></DIV></DIV>
<P><STRONG>命名(namespaces)空间</STRONG>－通常情况，只使用一个命名空间，称为主命名空间(main namespace)，但你是不会意识到这些的；为了创建可重用的macro、transforms或其它变量的集合(通常称库)，必须使用多命名空间，为了防止同名冲突。</P>
<P>首先创建一个库(假设保存在lib/my_test.ftl中)：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#macro&nbsp;</SPAN><SPAN style="COLOR: #ff0000">copyright&nbsp;date</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">p</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">Copyright&nbsp;(C)&nbsp;${date}&nbsp;Julia&nbsp;Smith.&nbsp;All&nbsp;rights&nbsp;reserved.<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&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">Email:&nbsp;${mail}</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">p</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">#macro</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#assign&nbsp;</SPAN><SPAN style="COLOR: #ff0000">mail&nbsp;</SPAN><SPAN style="COLOR: #0000ff">=&nbsp;"jsmith@acme.com"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN></DIV></DIV>
<P>使用import指令导入库到模板中，Freemarker会为导入的库创建新的命名空间，并可以通过import指令中指定的hash(散列)变量访问库中的变量：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#import&nbsp;</SPAN><SPAN style="COLOR: #ff0000">"/lib/my_test.ftl"&nbsp;as&nbsp;my</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">#assign&nbsp;</SPAN><SPAN style="COLOR: #ff0000">mail</SPAN><SPAN style="COLOR: #0000ff">="fred@acme.com"</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">@my</SPAN><SPAN style="COLOR: #ff0000">.copyright&nbsp;date</SPAN><SPAN style="COLOR: #0000ff">="1999-2002"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${my.mail}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${mail}&nbsp;&nbsp;</SPAN></DIV></DIV>
<P>结果：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">p</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">Copyright&nbsp;(C)&nbsp;1999-2002&nbsp;Julia&nbsp;Smith.&nbsp;All&nbsp;rights&nbsp;reserved.<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&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">Email:&nbsp;jsmith@acme.com</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">p</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>jsmith@acme.com<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>fred@acme.com&nbsp;&nbsp;</SPAN></DIV></DIV>
<P>上面的例子中使用的两个同名变量并没有冲突，因为它们位于不同的命名空间</P>
<P>可以使用assign指令在导入的命名空间中创建或替代变量：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#import&nbsp;</SPAN><SPAN style="COLOR: #ff0000">"/lib/my_test.ftl"&nbsp;as&nbsp;my</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${my.mail}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#assign&nbsp;</SPAN><SPAN style="COLOR: #ff0000">mail</SPAN><SPAN style="COLOR: #0000ff">="jsmith@other.com"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;in&nbsp;my</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${my.mail}&nbsp;&nbsp;</SPAN></DIV></DIV>
<P>结果：<BR><A href="mailto:jsmith@acme.com"><FONT color=#000000>jsmith@acme.com</FONT></A><BR><A href="mailto:jsmith@other.com"><FONT color=#000000>jsmith@other.com</FONT></A>&nbsp; </P>
<P>数据模型中的变量任何地方都可见，也包括不同的命名空间，下面修改了刚才创建的库：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#macro&nbsp;</SPAN><SPAN style="COLOR: #ff0000">copyright&nbsp;date</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">p</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">Copyright&nbsp;(C)&nbsp;${date}&nbsp;${user}.&nbsp;All&nbsp;rights&nbsp;reserved.</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">p</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">#macro</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">#assign&nbsp;</SPAN><SPAN style="COLOR: #ff0000">mail&nbsp;</SPAN><SPAN style="COLOR: #0000ff">=&nbsp;"${user}@acme.com"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;</SPAN></DIV></DIV>
<P>假设数据模型中的user变量的值是Fred：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#import&nbsp;</SPAN><SPAN style="COLOR: #ff0000">"/lib/my_test.ftl"&nbsp;as&nbsp;my</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">@my</SPAN><SPAN style="COLOR: #ff0000">.copyright&nbsp;date</SPAN><SPAN style="COLOR: #0000ff">="1999-2002"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${my.mail}</SPAN></DIV></DIV>
<P>&nbsp;结果：<BR>&nbsp;&lt;p&gt;Copyright (C) 1999-2002 Fred. All rights reserved.&lt;/p&gt;<BR><A href="mailto:Fred@acme.com"><FONT color=#000000>Fred@acme.com</FONT></A>&nbsp; <BR><BR><BR>参考：&nbsp;&nbsp; <A href="http://blog.csdn.net/chenyun2000/archive/2004/11/02/162979.aspx">chenyun'blog - FreeMarker设计指南</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A href="http://freemarker.sourceforge.net/">FreeMarker&nbsp; in sourceforge.net</A></P><img src ="http://www.blogjava.net/pepsixp/aggbug/1941.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pepsixp/" target="_blank">阿姆斯壮</a> 2005-03-11 11:08 <a href="http://www.blogjava.net/pepsixp/archive/2005/03/11/1941.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>学习FreeMarker（一）</title><link>http://www.blogjava.net/pepsixp/archive/2005/03/11/1685.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Fri, 11 Mar 2005 03:00:00 GMT</pubDate><guid>http://www.blogjava.net/pepsixp/archive/2005/03/11/1685.html</guid><wfw:comment>http://www.blogjava.net/pepsixp/comments/1685.html</wfw:comment><comments>http://www.blogjava.net/pepsixp/archive/2005/03/11/1685.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/pepsixp/comments/commentRss/1685.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pepsixp/services/trackbacks/1685.html</trackback:ping><description><![CDATA[<P>FreeMarker是一个用Java编写的模板引擎，主要用来生成HTML Web页面，特别是基于MVC模式的应用程序。虽然FreeMarker具有一些编程的能力，但不像PHP，通常由Java程序准备要显示的数据，由FreeMarker模板生成页面。&nbsp; FreeMarker可以作为Web应用框架一个组件，但它与容器无关，在非Web应用程序环境也能工作的很好。 FreeMarker适合作为MVC的视图组件，还能在模板中使用JSP标记库。</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><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></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">head</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">title</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">Welcome!</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">title</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">head</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">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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">h1</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">Welcome&nbsp;${user}!</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">h1</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">p</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">Our&nbsp;latest&nbsp;product:<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">a&nbsp;</SPAN><SPAN style="COLOR: #ff0000">href</SPAN><SPAN style="COLOR: #0000ff">="${latestProduct.url}"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">${latestProduct.name}</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">a</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">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><SPAN style="COLOR: #000000">&nbsp;&nbsp;<IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV>
<P>上面的例子中，在简单的HTML中加入了一些由${…}包围的特定FreeMarker的指令，这个文件就称为模板了。而user、latestProduct.url和latestProduct.name来自于数据模型，由Java程序提供，模板设计者就不用关心数据从哪来的。</P>
<P>FreeMarker模板中可以包括下面四种特定部分：<BR>一.) <STRONG>文本</STRONG>：直接输出<BR>二.) <STRONG>FTL标记</STRONG>(FreeMarker模板语言标记)：类似于HTML标记，名字前加#(有些以@开始，用户自定义标记)予以区分，不会输出。<BR><STRONG>字符串</STRONG>－ 使用单引号或双引号限定；如果包含特殊字符需要转义符：${"It's \"quoted\" andthis is a backslash: \\"}<BR>有一类特殊的字符串:${r"C:\foo\bar"}，输出结构为：C:\foo\bar，在引号前面加r被认为是纯文本。 <BR>数字－直接输入，不需要引号。${08}, ${+8}, ${8.00} and ${8} 都是相同的 <BR><STRONG>布尔值</STRONG>－true和false，不使用引号<BR><STRONG>Sequences(序列)</STRONG>－由逗号分隔的变量列表，由方括号限定，类似java中的一维数组：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#list&nbsp;</SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>["winter",&nbsp;"spring",&nbsp;"summer",&nbsp;"autumn"]&nbsp;as&nbsp;x</FONT></SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${x}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">#list</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV>
<P>输出结果：<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>winter<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>spring<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>summer<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>autumn<BR><BR>例二：[2 + 2, [1, 2, 3, 4], "whatnot"]<BR>例三：2..5，等同于[2, 3, 4, 5]；5..2，等同于[5,4,3,2]。注意方括号是不需要的。<BR><BR><STRONG>Hashes(散列)</STRONG>－由逗号分隔的键-值列表，由大括号限定，键和值之间用冒号分隔：{"name":"green mouse", "price":150}，键和值都是表达式，但是键必须是字符串。</P>
<P><STRONG>获取变量</STRONG>－${variable}，变量名只能是字母、数字、下划线、$、@和#的组合，且不能以数字开头。下列表达式是等价的：<BR>book.author.name<BR>book["author"].name<BR>book.author.["name"]<BR>book["author"]["name"]<BR><BR>获取Sequence(序列)片断－使用[startindex..endindex]，例如：seq中存储了"a", "b", "c", "d","e"，那么seq[1..2]包含了b和c两个值。<BR><BR>可以使用.variablename语法访问FreeMarker内置变量。</P>
<P><STRONG>字符串操作</STRONG><BR>{"Hello ${user}!"} &lt;==&gt; ${"Hello " + user + "!"}<BR>${"${user}${user}${user}${user}"} &lt;==&gt; ${user + user + user + user}</P>
<P>${…}只能在文本中使用，下面是错误的代码：<BR>&lt;#if ${isBig}&gt;Wow!&lt;/#if&gt; <BR>&lt;#if "${isBig}"&gt;Wow!&lt;/#if&gt;&nbsp; //此处的代码也是错误的，因为if指令需要的是boolean，实际的却是个字符串</P>
<P>子字符串的操作，假设user的值为"Big Joe"：<BR>${user[0]}${user[4]}&nbsp; &lt;==&gt;&nbsp; BJ<BR>${user[1..4]}&nbsp; &lt;==&gt; ig J </P>
<P><STRONG>Sequences(序列)操作</STRONG></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#list&nbsp;</SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>["Joe",&nbsp;"Fred"]&nbsp;+&nbsp;["Julia",&nbsp;"Kate"]&nbsp;as&nbsp;user</FONT></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;${user}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">#list</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV>
<P>结果：<BR>- Joe<BR>- Fred<BR>- Julia<BR>- Kate</P>
<P><STRONG>Hashes(散列)操作</STRONG></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><STRONG><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></STRONG><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#assign&nbsp;</SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>ages</FONT>&nbsp;</SPAN><SPAN style="COLOR: #0000ff">=&nbsp;<FONT color=#000000>{"Joe":23,&nbsp;</FONT></SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>"Fred":25}&nbsp;+&nbsp;{"Joe":30,&nbsp;"Julia":18}</FONT></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;Joe&nbsp;is&nbsp;${ages.Joe}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>-&nbsp;Fred&nbsp;is&nbsp;${ages.Fred}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>-&nbsp;Julia&nbsp;is&nbsp;${ages.Julia}&nbsp;&nbsp;</SPAN></DIV></DIV>
<P>结果：<BR>- Joe is 30<BR>- Fred is 25<BR>- Julia is 18&nbsp; </P>
<P><STRONG>算术运算</STRONG></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><STRONG><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></STRONG><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>x的值设定为5</FONT>&nbsp;--</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${x&nbsp;*&nbsp;x&nbsp;-&nbsp;100}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${x&nbsp;/&nbsp;2}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${12&nbsp;%&nbsp;10}</SPAN></DIV></DIV>
<P>结果：<BR>-75<BR>2.5<BR>2 <BR><BR>注意： 操作符两边必须是数字；使用"+"时，如果一边是数字，一边是字符串，就会自动将数字转换为字符串。<BR><BR>使用内建的指令int<STRONG>获得整数部分</STRONG>：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV>${(x/2)?int}<BR>${1.1?int}<BR>${1.999?int}<BR>${-1.1?int}<BR>${-1.999?int}</DIV></DIV>
<P>结果：<BR>2<BR>1<BR>1<BR>-1<BR>-1</P>
<P><STRONG>比较操作符</STRONG>－&lt;#if expression&gt;...&lt;/#if&gt;<BR>1.)使用=（或==，完全相等）测试两个值是否相等，使用!= 测试两个值是否不相等<BR>2.)=和!=两边必须是相同类型的值，否则会产生错误，例如&lt;#if 1 = "1"&gt;会引起错误<BR>3.)Freemarker是精确比较，所以"x"、"x&nbsp; "和"X"是不相等的<BR>4.)对数字和日期可以使用&lt;、&lt;=、&gt;和&gt;=，但不能用于字符串<BR>5.)由于Freemarker会将&gt;解释成FTL标记的结束字符，所以对于&gt;和&gt;=可以使用括号来避免这种情况，例如&lt;#if (x &gt; y)&gt;，另一种替代的方法是，使用lt、lte、gt和gte来替代&lt;、&lt;=、&gt;和&gt;=</P>
<P><STRONG>逻辑操作符</STRONG>－&amp;&amp;(and)、||(or)、!(not)，只能用于布尔值，否则会产生错误<BR>&lt;#if x &lt; 12 &amp;&amp; color = "green"&gt;<BR>&nbsp; We have less than 12 things, and they are green.<BR>&lt;/#if&gt;<BR>&lt;#if !hot&gt; &lt;#-- here hot must be a boolean --&gt;<BR>&nbsp; It's not hot.<BR>&lt;/#if&gt;&nbsp; </P>
<P><STRONG>内置函数</STRONG>－用法类似访问hash(散列)的子变量，只是使用"?"替代"."，例如：user?upper_case<BR>下面列出常用的一些函数：<BR><U>对于字符串</U><BR>html－对字符串进行HTML编码<BR>cap_first－使字符串第一个字母大写<BR>lower_case－将字符串转换成小写<BR>trim－去掉字符串前后的空白字符<BR><U>对于Sequences(序列)<BR></U>size－获得序列中元素的数目<BR><U>对于数字<BR></U>int－取得数字的整数部分（如-1.9?int的结果是-1）<BR><BR>例一：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>test的值为Tom&nbsp;&amp;&nbsp;Jerry</FONT>&nbsp;--</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${test?html}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${test?upper_case?html}</SPAN></DIV></DIV>
<P>结果：<BR>Tom &amp;amp; Jerry<BR>TOM &amp;amp; JERRY <BR><BR>例二：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>seasons的值为"winter",&nbsp;"spring",&nbsp;"summer",&nbsp;"autumn"</FONT>&nbsp;--</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${seasons?size}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${seasons[1]?cap_first}&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>left&nbsp;side&nbsp;can&nbsp;by&nbsp;any&nbsp;expression</FONT>&nbsp;--</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${"horse"?cap_first}&nbsp;&nbsp;</SPAN></DIV></DIV>
<P>结果：<BR>4<BR>Spring<BR>Horse&nbsp; </P>
<P><STRONG>方法的调用</STRONG><BR>${repeat("What", 3)} <BR>${repeat(repeat("x", 2), 3) + repeat("What", 4)?upper_case} <BR>结果：<BR>WhatWhatWhat<BR>xxxxxxWHATWHATWHATWHAT </P>
<P><STRONG>操作符优先顺序</STRONG><BR>后缀&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [subvarName] [subStringRange] . (methodParams)<BR>一元&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +expr、-expr、!<BR>内建&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;?<BR>乘法&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; *、 / 、%<BR>加法&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; +、-<BR>关系&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&lt;、&gt;、&lt;=、&gt;=（lt、lte、gt、gte）<BR>相等&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =、!=<BR>逻辑&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &amp;&amp;<BR>逻辑&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;||<BR>数字范围&nbsp;&nbsp; &nbsp;&nbsp; ..</P>
<P>三.) <STRONG>Interpolation</STRONG>：由${...}或#{...}两种类型，输出计算值，可以定义输出的格式<BR>例一：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#setting&nbsp;</SPAN><SPAN style="COLOR: #ff0000">number_format</SPAN><SPAN style="COLOR: #0000ff">="currency"</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">#assign&nbsp;</SPAN><SPAN style="COLOR: #ff0000">answer</SPAN><SPAN style="COLOR: #0000ff">=42/&gt;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>${answer}<BR></FONT><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><FONT color=#000000>${answer?string}</FONT>&nbsp;&nbsp;<FONT color=#000000>&lt;#--&nbsp;the&nbsp;same&nbsp;as&nbsp;${answer}&nbsp;--</FONT></SPAN><SPAN style="COLOR: #0000ff"><FONT color=#000000>&gt;</FONT></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${answer?string.number}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${answer?string.currency}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${answer?string.percent}&nbsp;</SPAN></DIV></DIV>
<P>结果：<BR>$42.00<BR>$42.00<BR>42<BR>$42.00<BR>4,200%</P>
<P>例二：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">${lastUpdated?string("yyyy-MM-dd&nbsp;HH:mm:ss&nbsp;zzzz")}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${lastUpdated?string("EEE,&nbsp;MMM&nbsp;d,&nbsp;''yy")}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>${lastUpdated?string("EEEE,&nbsp;MMMM&nbsp;dd,&nbsp;yyyy,&nbsp;hh:mm:ss&nbsp;a&nbsp;'('zzz')'")}&nbsp;&nbsp;</SPAN></DIV></DIV>
<P>结果：<BR>2003-04-08 21:24:44 Pacific Daylight Time<BR>Tue, Apr 8, '03<BR>Tuesday, April 08, 2003, 09:24:44 PM (PDT)</P>
<P>例三：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#assign&nbsp;</SPAN><SPAN style="COLOR: #ff0000">foo</SPAN><SPAN style="COLOR: #0000ff">=true/&gt;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>${foo?string("yes",&nbsp;"no")}</FONT></SPAN></DIV></DIV>
<P>结果：<BR>yes</P>
<P>例四：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>x&nbsp;is&nbsp;2.582&nbsp;and&nbsp;y&nbsp;is&nbsp;4</FONT>&nbsp;--</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#{x;&nbsp;M2}&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--<FONT color=#0000ff>&nbsp;</FONT></SPAN><SPAN style="COLOR: #ff0000"><FONT color=#0000ff>2.58</FONT>&nbsp;--</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#{y;&nbsp;M2}&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000"><FONT color=#0000ff>4&nbsp;</FONT>&nbsp;&nbsp;&nbsp;--</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#{x;&nbsp;m1}&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000"><FONT color=#0000ff>2.6</FONT>&nbsp;--</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#{y;&nbsp;m1}&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000"><FONT color=#0000ff>4.0</FONT>&nbsp;--</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#{x;&nbsp;m1M2}&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000"><FONT color=#0000ff>2.58</FONT>&nbsp;--</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#{y;&nbsp;m1M2}&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#--&nbsp;</SPAN><SPAN style="COLOR: #ff0000"><FONT color=#0000ff>4.0</FONT>&nbsp;&nbsp;--</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;</SPAN></DIV></DIV>
<P>说明：mX－小数部分最小X位；MX－小数部分最大X位。</P>
<P>四.) <STRONG>注释</STRONG>：&lt;#--和--&gt; </P>
<P>下面是一个常用的模板例子：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">p</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">We&nbsp;have&nbsp;these&nbsp;animals:<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">table&nbsp;</SPAN><SPAN style="COLOR: #ff0000">border</SPAN><SPAN style="COLOR: #0000ff">=1&gt;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #ff0000">&lt;tr</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;</SPAN><SPAN style="COLOR: #800000">th</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">Name</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">th</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">Price<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#list&nbsp;</SPAN><SPAN style="COLOR: #ff0000">animals&nbsp;as&nbsp;being</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">tr</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">td</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#if&nbsp;</SPAN><SPAN style="COLOR: #ff0000">being.size&nbsp;</SPAN><SPAN style="COLOR: #0000ff">=&nbsp;"large"</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;</SPAN><SPAN style="COLOR: #800000">b</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;/</SPAN><SPAN style="COLOR: #800000">#if</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;${being.name}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#if&nbsp;</SPAN><SPAN style="COLOR: #ff0000">being.size</SPAN><SPAN style="COLOR: #0000ff">="large"</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;/</SPAN><SPAN style="COLOR: #800000">b</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;/</SPAN><SPAN style="COLOR: #800000">#if</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">td</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">${being.price}&nbsp;Euros<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">#list</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">table</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">#include&nbsp;</SPAN><SPAN style="COLOR: #ff0000">"/copyright_footer.html"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV></DIV>
<P><STRONG>注意点</STRONG>：<BR>1.) FreeMarker是区分大小写的；<BR>2.) FTL标记不能位于另一个FTL标记内部，例如：&lt;#if &lt;#include 'foo'&gt;='bar'&gt;...&lt;/if&gt;；<BR>3.) ${…}只能在文本中使用；<BR>4.) 多余的空白字符会在模板输出时去除；<BR>5.) 如果使用的指令不存在，会产生一个错误消息。</P>
<P><BR>参考：&nbsp;&nbsp;&nbsp; <A href="http://blog.csdn.net/chenyun2000/archive/2004/11/02/162979.aspx">chenyun'blog - FreeMarker设计指南</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <A href="http://freemarker.sourceforge.net/">FreeMarker&nbsp; in sourceforge.net</A></P><img src ="http://www.blogjava.net/pepsixp/aggbug/1685.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pepsixp/" target="_blank">阿姆斯壮</a> 2005-03-11 11:00 <a href="http://www.blogjava.net/pepsixp/archive/2005/03/11/1685.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>J2EE中的分页(翻译)</title><link>http://www.blogjava.net/pepsixp/archive/2005/02/22/1429.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Tue, 22 Feb 2005 14:33:00 GMT</pubDate><guid>http://www.blogjava.net/pepsixp/archive/2005/02/22/1429.html</guid><wfw:comment>http://www.blogjava.net/pepsixp/comments/1429.html</wfw:comment><comments>http://www.blogjava.net/pepsixp/archive/2005/02/22/1429.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/pepsixp/comments/commentRss/1429.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pepsixp/services/trackbacks/1429.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 分页是一种最简单且广泛使用的方法，可以把大数据集分成小的数据块。它是Web站点设计的一个核心部分，包括UI，即客户端(管理屏幕显示的内容)和服务器端(高效处理大结果集，防止资源的大量消耗及服务的时延)。分页机制需要基于以下两个条件：1.) 屏幕显示的信息是受限的。2.) 资源配置－数据库连接数和内存的使用量。分页机制有两种方式：...&nbsp;&nbsp;<a href='http://www.blogjava.net/pepsixp/archive/2005/02/22/1429.html'>阅读全文</a><img src ="http://www.blogjava.net/pepsixp/aggbug/1429.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pepsixp/" target="_blank">阿姆斯壮</a> 2005-02-22 22:33 <a href="http://www.blogjava.net/pepsixp/archive/2005/02/22/1429.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Tom小猫，让我看清你的五脏六腑（三） </title><link>http://www.blogjava.net/pepsixp/archive/2005/02/18/1305.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Fri, 18 Feb 2005 14:41:00 GMT</pubDate><guid>http://www.blogjava.net/pepsixp/archive/2005/02/18/1305.html</guid><wfw:comment>http://www.blogjava.net/pepsixp/comments/1305.html</wfw:comment><comments>http://www.blogjava.net/pepsixp/archive/2005/02/18/1305.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pepsixp/comments/commentRss/1305.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pepsixp/services/trackbacks/1305.html</trackback:ping><description><![CDATA[<P><STRONG>Servlet过滤器</STRONG><BR>在Java Servlet2.3中定义，能够对Servlet容器的请求和响应对象进行检查和修改。所有的过滤器类都必须实现javax.servlet.Filter接口，其中<STRONG>有三个需要实现的方法</STRONG>：<BR>init(FilterConfig)－一个初始化方法，Servlet容器创建过滤器类后将调用这个方法，在此方法中可以读取web.xml文件中的Servlet过滤器的初始化参数。<BR>doFilter(ServletRequest,ServletResponse,FilterChain)－实际的过滤操作，FilterChain参数用于访问后面的过滤器。<BR>destroy()－用来释放某些Servlet过滤器占用的资源。</P>
<P>下面是一个解决中文乱码问题很有用的一个过滤器：</P>
<P></P>
<P></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><STRONG><IMG id=Codehighlighter1_58_399_Open_Image onclick="this.style.display='none'; Codehighlighter1_58_399_Open_Text.style.display='none'; Codehighlighter1_58_399_Closed_Image.style.display='inline'; Codehighlighter1_58_399_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_58_399_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_58_399_Closed_Text.style.display='none'; Codehighlighter1_58_399_Open_Image.style.display='inline'; Codehighlighter1_58_399_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></STRONG><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;SetCharacterEncodingFilter&nbsp;implements&nbsp;Filter&nbsp;</SPAN><SPAN id=Codehighlighter1_58_399_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_58_399_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG id=Codehighlighter1_91_92_Open_Image onclick="this.style.display='none'; Codehighlighter1_91_92_Open_Text.style.display='none'; Codehighlighter1_91_92_Closed_Image.style.display='inline'; Codehighlighter1_91_92_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_91_92_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_91_92_Closed_Text.style.display='none'; Codehighlighter1_91_92_Open_Image.style.display='inline'; Codehighlighter1_91_92_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;destroy()&nbsp;</SPAN><SPAN id=Codehighlighter1_91_92_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_91_92_Open_Text><SPAN style="COLOR: #000000">{}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;doFilter(ServletRequest&nbsp;request,&nbsp;ServletResponse&nbsp;response,FilterChain&nbsp;chain)<BR><IMG id=Codehighlighter1_231_321_Open_Image onclick="this.style.display='none'; Codehighlighter1_231_321_Open_Text.style.display='none'; Codehighlighter1_231_321_Closed_Image.style.display='inline'; Codehighlighter1_231_321_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_231_321_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_231_321_Closed_Text.style.display='none'; Codehighlighter1_231_321_Open_Image.style.display='inline'; Codehighlighter1_231_321_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throws&nbsp;IOException,&nbsp;ServletException&nbsp;</SPAN><SPAN id=Codehighlighter1_231_321_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_231_321_Open_Text><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;request.setCharacterEncoding(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">GB2312</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;chain.doFilter(request,&nbsp;response);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_396_397_Open_Image onclick="this.style.display='none'; Codehighlighter1_396_397_Open_Text.style.display='none'; Codehighlighter1_396_397_Closed_Image.style.display='inline'; Codehighlighter1_396_397_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_396_397_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_396_397_Closed_Text.style.display='none'; Codehighlighter1_396_397_Open_Image.style.display='inline'; Codehighlighter1_396_397_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;init(FilterConfig&nbsp;filterConfig)&nbsp;throws&nbsp;ServletException&nbsp;</SPAN><SPAN id=Codehighlighter1_396_397_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_396_397_Open_Text><SPAN style="COLOR: #000000">{}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV></DIV>
<P><STRONG>发布Servlet过滤器</STRONG>－在web.xml在文件中加入&lt;filter&gt;元素和&lt;filter-mapping&gt;元素</P>
<P>下面的例子中Servlet过滤器会过滤所有的URL：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">filter</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">filter-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">Set&nbsp;Character&nbsp;Encoding</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">filter-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">filter-class</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">SetCharacterEncodingFilter</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">filter-class</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">filter</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">filter-mapping</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">filter-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">Set&nbsp;Character&nbsp;Encoding</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">filter-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></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">url-pattern</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">/*</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">url-pattern</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">filter-mapping</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV>
<P><STRONG>串连Servlet过滤器</STRONG><BR>多个Servlet过滤器可以协同工作，Servlet容器将根据它们在web.xml中定义的先后顺序，依次调用它们的doFilter()方法。<BR>工作流程如下：<BR>&nbsp;Code1; // 表示调用chain.doFilter()前面的代码<BR>&nbsp;chain.doFilter();&nbsp; // 表示调用下一个过滤器的doFilter()方法<BR>&nbsp;Code2; // 表示调用chain.doFilter()后面的代码</P>
<P><STRONG>自定义JSP标签库<BR></STRONG>此技术在JSP 1.1版本中才出现，用来重用某些复杂的逻辑运算和事务，或定义JSP王爷的输出内容和格式。制作一个完整的自定义标签程序，包含3个步骤：<BR><BR><STRONG>1. 创建标签的处理类<BR></STRONG>此类必须扩展javax.servlet.jsp.TagSupport类或者javax.servlet.jsp.BodyTagSupport类。<BR>以TagSupport类为例，先了解一下这个类的主要方法：<BR>doStartTag()－JSP容器遇到自定义标签的起始标志时调用该方法；<BR>doEndTag()－JSP容器遇到自定义标签的结束标志时调用该方法；<BR>setValue(String k,Object o)－在标签处理类中设置key/value;<BR>getValue(String k)－在标签处理类中根据key返回匹配的value;<BR>removeValue(String k)－在标签处理类中删除key/value;<BR>setPageContext(PageContext pc)－设置PageContext对象，该方法在调用doStartTag()和doStartTag()前调用；<BR>setParent(Tag t)－设置嵌套当前标签的上层标签的处理类，该方法在调用doStartTag()和doStartTag()前调用；<BR>getParent()－返回嵌套当前标签的上层标签的处理类。<BR><BR>首先调用setPageContext(PageContext pc)和setParent(Tag t)，设置TagSupport类的两个重要属性值。<BR><BR>如果遇到起始标志，调用doStartTag()，此方法返回一个整数值，它有两个可选值：Tag.SKIP_BODY(标签之间的内容被忽略)和Tag.EVAL_BODY_INCLUDE(标签之间的内容正常执行)。<BR>例如：&lt;prefix:mytag&gt;test&lt;/prefix:mytag&gt;，如果遇上Tag.SKIP_BODY，test字符串不会显示在页面上；如果遇上Tag.EVAL_BODY_INCLUDE，test字符串将会显示在页面上。<BR><BR>如果遇到结束标志，调用doEndTag()，此方法也返回一个整数值，它有两个可选值：Tag.SKIP_PAGE(表示立刻停止执行JSP页面，网页上未处理的静态内容和JSP程序均别忽略，任何已有的输出内容立刻返回到客户端；)和Tag.EVAL_PAGE(表示按正常流程继续执行JSP页面)。<BR><BR>如果自定义标签包含自定义的属性，例如：&lt;prefix:mytag attribute1="value1"&gt;，那么处理类中应该将这个属性做为成员变量，并提供一组get和set方法：<BR>private int attribute1;<BR>public void setAttribute1(int value){<BR>&nbsp;this.attriubte1 = value;<BR>}<BR>public int getAttribute1(){<BR>&nbsp;return attribute1;<BR>}<BR><BR>下面是一个用来验证用户登陆的标签处理类例子：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG id=Codehighlighter1_48_630_Open_Image onclick="this.style.display='none'; Codehighlighter1_48_630_Open_Text.style.display='none'; Codehighlighter1_48_630_Closed_Image.style.display='inline'; Codehighlighter1_48_630_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_48_630_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_48_630_Closed_Text.style.display='none'; Codehighlighter1_48_630_Open_Image.style.display='inline'; Codehighlighter1_48_630_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;ValidateLoginTag&nbsp;extends&nbsp;TagSupport</SPAN><SPAN id=Codehighlighter1_48_630_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_48_630_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: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;String&nbsp;name;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;String&nbsp;password;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;Log&nbsp;log&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;LogFactory.getLog(ValidateLoginTag.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_215_344_Open_Image onclick="this.style.display='none'; Codehighlighter1_215_344_Open_Text.style.display='none'; Codehighlighter1_215_344_Closed_Image.style.display='inline'; Codehighlighter1_215_344_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_215_344_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_215_344_Closed_Text.style.display='none'; Codehighlighter1_215_344_Open_Image.style.display='inline'; Codehighlighter1_215_344_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;doEndTag()&nbsp;throws&nbsp;JspException</SPAN><SPAN id=Codehighlighter1_215_344_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_215_344_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_280_310_Open_Image onclick="this.style.display='none'; Codehighlighter1_280_310_Open_Text.style.display='none'; Codehighlighter1_280_310_Closed_Image.style.display='inline'; Codehighlighter1_280_310_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_280_310_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_280_310_Closed_Text.style.display='none'; Codehighlighter1_280_310_Open_Image.style.display='inline'; Codehighlighter1_280_310_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(name.equals(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">pepsixp</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN style="COLOR: #000000">&amp;&amp;</SPAN><SPAN style="COLOR: #000000">&nbsp;password.equals(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">888888</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">))</SPAN><SPAN id=Codehighlighter1_280_310_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_280_310_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;&nbsp; </SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">(EVAL_PAGE);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;(SKIP_PAGE);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_375_402_Open_Image onclick="this.style.display='none'; Codehighlighter1_375_402_Open_Text.style.display='none'; Codehighlighter1_375_402_Closed_Image.style.display='inline'; Codehighlighter1_375_402_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_375_402_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_375_402_Closed_Text.style.display='none'; Codehighlighter1_375_402_Open_Image.style.display='inline'; Codehighlighter1_375_402_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;String&nbsp;getName()&nbsp;</SPAN><SPAN id=Codehighlighter1_375_402_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_375_402_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">return</SPAN><SPAN style="COLOR: #000000">&nbsp;name;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_442_474_Open_Image onclick="this.style.display='none'; Codehighlighter1_442_474_Open_Text.style.display='none'; Codehighlighter1_442_474_Closed_Image.style.display='inline'; Codehighlighter1_442_474_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_442_474_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_442_474_Closed_Text.style.display='none'; Codehighlighter1_442_474_Open_Image.style.display='inline'; Codehighlighter1_442_474_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;setName(String&nbsp;name)&nbsp;</SPAN><SPAN id=Codehighlighter1_442_474_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_442_474_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">this</SPAN><SPAN style="COLOR: #000000">.name&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;name;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_509_540_Open_Image onclick="this.style.display='none'; Codehighlighter1_509_540_Open_Text.style.display='none'; Codehighlighter1_509_540_Closed_Image.style.display='inline'; Codehighlighter1_509_540_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_509_540_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_509_540_Closed_Text.style.display='none'; Codehighlighter1_509_540_Open_Image.style.display='inline'; Codehighlighter1_509_540_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;String&nbsp;getPassword()&nbsp;</SPAN><SPAN id=Codehighlighter1_509_540_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_509_540_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">return</SPAN><SPAN style="COLOR: #000000">&nbsp;password;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_588_628_Open_Image onclick="this.style.display='none'; Codehighlighter1_588_628_Open_Text.style.display='none'; Codehighlighter1_588_628_Closed_Image.style.display='inline'; Codehighlighter1_588_628_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_588_628_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_588_628_Closed_Text.style.display='none'; Codehighlighter1_588_628_Open_Image.style.display='inline'; Codehighlighter1_588_628_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;setPassword(String&nbsp;password)&nbsp;</SPAN><SPAN id=Codehighlighter1_588_628_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_588_628_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">this</SPAN><SPAN style="COLOR: #000000">.password&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;password;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV></DIV>
<P><STRONG>2.创建TLD</STRONG>－Tag Library Descriptor(标签库描述文件)<BR>TLD文件中元素可以分为三类：&lt;tablib&gt;、&lt;tag&gt;、&lt;attribute&gt;<BR>&lt;tablib&gt;－设定标签库的相关信息，包含的子元素有tlibversion、jspversion、shortname、uri、info、tag。<BR>&lt;tag&gt;－用来定义一个标签，包含的子元素有name、tagcalss、bodycontent、info、attribute。<BR>bodycontent的说明：有三个可选值empty、JSP、tagdependent，empty表示标签中没有body，JSP表示body中可以加入JSP程序代码，tagdependent表示body的内容有标签进行处理。<BR>&lt;attribute&gt;－用来定义标签的属性，包含的子元素有name、required、rtexprvalue。<BR>rtexprvalue的说明：表示是否可以使用&lt;%=...%&gt;类型的表达式，<BR>例如：&lt;prefix:mytaglib attribute1="&lt;%=name%&gt;"&gt;<BR>下面是一个简单的TLD文件：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;?</SPAN><SPAN style="COLOR: #ff00ff">xml&nbsp;version="1.0"&nbsp;encoding="UTF-8"</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: #ff00ff">DOCTYPE&nbsp;taglib&nbsp;PUBLIC&nbsp;"-//Sun&nbsp;Microsystems,&nbsp;Inc.//DTD&nbsp;JSP&nbsp;Tag&nbsp;Library&nbsp;1.1//EN"&nbsp;"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"</SPAN><SPAN style="COLOR: #0000ff">&gt;</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></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">taglib</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">tlibversion</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">1.2</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">tlibversion</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">jspversion</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">1.1</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">jspversion</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">shortname</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">MY&nbsp;Tag&nbsp;Library</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">shortname</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">uri</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">http://www.blogjava.net/pepsixp/</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">uri</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">info</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/dot.gif"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">info</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">tag</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">ifLogin</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">tagclass</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">com.akazam.struts.taglib.ValidateLoginTag</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">tagclass</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">bodycontent</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">empty</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">bodycontent</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">info</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/dot.gif"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">info</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">attribute</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">name</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">required</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">true</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">required</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">rtexprvalue</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">true</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">rtexprvalue</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">attribute</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">attribute</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">password</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">required</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">true</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">required</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">rtexprvalue</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">true</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">rtexprvalue</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">attribute</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">tag</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">taglib</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></DIV></DIV>
<P>实际中的使用：<BR>&lt;%@ taglib uri="/tags/test" prefix="test" %&gt;<BR>&lt;test:ifLogin name="pepsixp" password="888888"/&gt;<BR><BR>3.<STRONG>在web应用中使用标签</STRONG><BR>先要在web.xml文件加入声明引用标签所在的标签：<BR></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">taglib</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">taglib-uri</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">/tags/test</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">taglib-uri</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">taglib-location</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">/WEB-INF/test.tld</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">taglib-location</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">taglib</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV></DIV>
<P><FONT color=#808080><BR>参考：《Tomcat与JavaWeb开发技术详解》</FONT></P><img src ="http://www.blogjava.net/pepsixp/aggbug/1305.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pepsixp/" target="_blank">阿姆斯壮</a> 2005-02-18 22:41 <a href="http://www.blogjava.net/pepsixp/archive/2005/02/18/1305.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Tom小猫，让我看清你的五脏六腑（二）</title><link>http://www.blogjava.net/pepsixp/archive/2005/02/16/1261.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Wed, 16 Feb 2005 15:29:00 GMT</pubDate><guid>http://www.blogjava.net/pepsixp/archive/2005/02/16/1261.html</guid><wfw:comment>http://www.blogjava.net/pepsixp/comments/1261.html</wfw:comment><comments>http://www.blogjava.net/pepsixp/archive/2005/02/16/1261.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pepsixp/comments/commentRss/1261.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pepsixp/services/trackbacks/1261.html</trackback:ping><description><![CDATA[<P><FONT style="BACKGROUND-COLOR: #ffffff"><STRONG></P>
<P>安全域</STRONG><BR>这是Tomcat服务器用来保护Web应用资源的一种机制。一个用户可以拥有一个或多个角色，每个角色限定了可访问的Web资源，这样就将用户和Web资源对应起来了。在org.apache.catalina.Realm接口中声名了将用户名、口令和角色相管理的方法，Tomcat5提供了4个实现这一接口的类，分别为：MemoryRealm(XML文件读取)、JDBCRealm(JDBC驱动程序读取)、DataSourceRealm(JNDI数据源读取)、JNDIRealm(JNDI provider读取LDAP的目录服务器信息)。</FONT></P>
<P><FONT style="BACKGROUND-COLOR: #ffffff"><STRONG>Web资源的设置<BR></STRONG>需要在web.xml文件中加入&lt;security-constraint&gt;、&lt;login-config&gt;、&lt;security-role&gt;元素。<BR>例如在Tomcat的admin应用中的配置：</FONT><FONT style="BACKGROUND-COLOR: #ffffff"><BR></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">security-constraint</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff"><FONT color=#000000>&nbsp;&nbsp;&nbsp; </FONT>&lt;</SPAN><SPAN style="COLOR: #800000">display-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">Tomcat&nbsp;Server&nbsp;Configuration&nbsp;Security&nbsp;Constraint</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">display-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff"><FONT color=#000000>&nbsp;&nbsp;&nbsp; </FONT>&lt;</SPAN><SPAN style="COLOR: #800000">web-resource-collection</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff"><FONT color=#000000>&nbsp;&nbsp;&nbsp; </FONT>&lt;</SPAN><SPAN style="COLOR: #800000">web-resource</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">Protected&nbsp;Area</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">web-resource</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</SPAN><SPAN style="COLOR: #800000">url-pattern</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">*.htm</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">url-pattern</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</SPAN><SPAN style="COLOR: #800000">url-pattern</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">*.jsp</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">url-pattern</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</SPAN><SPAN style="COLOR: #800000">url-pattern</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">*.do</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">url-pattern</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff"><FONT color=#000000>&nbsp;&nbsp;&nbsp; </FONT>&lt;/</SPAN><SPAN style="COLOR: #800000">web-resource-collection</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&nbsp;&nbsp;&nbsp; &lt;</SPAN><SPAN style="COLOR: #800000">auth-constraint</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</SPAN><SPAN style="COLOR: #800000">role-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">admin</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">role-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&nbsp;&nbsp;&nbsp; &lt;/</SPAN><SPAN style="COLOR: #800000">auth-constraint</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">security-constraint</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV>
<P>上面的代码表明：只有admin角色才能访问admin应用中的*.jsp、*.do和*.html资源。<BR>另一个例子是jsp-examples应用：<BR></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">sercurity-constraint</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&nbsp;&nbsp;&nbsp; &lt;</SPAN><SPAN style="COLOR: #800000">display-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">Tomcat&nbsp;Server&nbsp;Configuration&nbsp;Security&nbsp;Constraint</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">display-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&nbsp;&nbsp;&nbsp; &lt;</SPAN><SPAN style="COLOR: #800000">web-resource-collection</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</SPAN><SPAN style="COLOR: #800000">web-resource</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">Protected&nbsp;Area</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">web-resource</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</SPAN><SPAN style="COLOR: #800000">url-pattern</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">/security/protected/*</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">url-pattern</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</SPAN><SPAN style="COLOR: #800000">http-method</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">DELETE</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">http-method</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">http-method</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">GET</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">http-method</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">http-method</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">POST</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">http-method</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">http-method</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">PUT</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">http-method</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff"><FONT color=#000000>&nbsp;&nbsp;&nbsp; </FONT>&lt;/</SPAN><SPAN style="COLOR: #800000">web-resource-collection</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&nbsp;&nbsp;&nbsp; &lt;</SPAN><SPAN style="COLOR: #800000">auth-constraint</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff"><FONT color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT>&lt;</SPAN><SPAN style="COLOR: #800000">role-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">tomcat</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">role-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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">role-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">role1</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">role-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; </SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">auth-constraint</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">security-constraint</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV>
<P>上面的代码表明：只要tomcat和role1角色才可以以DELETE、GET、POST和GET方式访问jsp-exzmples应用URL为/security/protected/下的资源。<BR>在web.xml中加入&lt;login-config&gt;元素－系统会以对话框的方式进行登陆<BR></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">login-config</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&nbsp;&nbsp;&nbsp; &lt;</SPAN><SPAN style="COLOR: #800000">auth-method</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">FORM</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">auth-method</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">realm-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">Tomcat&nbsp;Configuration&nbsp;Form-Baseed&nbsp;Authenticaton&nbsp;Area</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">realm-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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">from-login-config</SPAN><SPAN style="COLOR: #0000ff">&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">from-login-page</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">/login/login.jsp</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">from-login-page</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">from-error-page</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">/error.jsp</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">from-error-page</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">from-login-config</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">login-config</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV>
<P>&lt;auth-method&gt;有三个可选项：BASIC、DIGEST、FORM。<BR>BASIC－基本验证：访问受保护资源时，会弹出一对话框。要求输入用户名和密码，如果连续3次失败后，会显示一个错误页面。这个方法的缺点是用户名和密码的数据传输采用的是Base64编码(可读文本)，是非常不安全的。<BR>DIGEST－摘要验证：数据采用MD5对用户名和密码进行加密，然后再传输，显然这种方法很安全。<BR>FORM－表单验证：可以使用自定义的登陆页面，但用户名对应的文本框名称必须是j_username,密码为j_password，且表单action值为j_security_check。<BR>在web.xml中加入&lt;security-role&gt;元素－指明这个Web应用应用的所有角色的名字<BR></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">security-role</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff"><FONT color=#000000>&nbsp;&nbsp;&nbsp; </FONT>&lt;</SPAN><SPAN style="COLOR: #800000">description</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">The&nbsp;role&nbsp;that&nbsp;is&nbsp;required&nbsp;to&nbsp;lon&nbsp;in&nbsp;to&nbsp;the&nbsp;Administration&nbsp;Application.</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">description</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">role-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">admin</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">role-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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">role-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">friend</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">role-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">security-role</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV>
<P>你可以调用HttpRequeset接口的getRemoteUser()方法返回当前用户的名字：&lt;%=request.getRemoteUser()%&gt;</FONT></P><FONT style="BACKGROUND-COLOR: #ffffff">
<P><BR><STRONG>内存域</STRONG>－由org.apache.catalina.realm.MemoryRelam类实现<BR>小猫启动时，自动读取&lt;%CATALINA_HOME%&gt;/conf/tomcat-users.xml文件，要在Web应用中使用，可以在对应的&lt;Context&gt;元素内加入如下内容：&lt;Realm className="org.apache.catalina.realm.MemoryRelam"/&gt;</P>
<P><STRONG>JDBC域</STRONG>－通过JDBC驱动从数据库中直接读取验证信息，通过验证后，信息会存储在session中。<BR>在mysql中新建两张表：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><SPAN style="COLOR: #0000ff">create</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">table</SPAN><SPAN style="COLOR: #000000">&nbsp;users{</SPAN><SPAN style="COLOR: #ff00ff">user_name</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #000000">varchar</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">15</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN style="COLOR: #808080">not</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">primary</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">key</SPAN><SPAN style="COLOR: #000000">,user_pass&nbsp;</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #000000">varchar</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">15</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN style="COLOR: #808080">not</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">&nbsp;};<BR></SPAN><SPAN style="COLOR: #0000ff">create</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">table</SPAN><SPAN style="COLOR: #000000">&nbsp;usr_roles{usr_name&nbsp;</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #000000">varchar</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">15</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN style="COLOR: #808080">not</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">,role_name&nbsp;</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #000000">varchar</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">15</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN style="COLOR: #808080">not</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">,<BR></SPAN><SPAN style="COLOR: #0000ff">&nbsp;&nbsp;primary</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">key</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #ff00ff">user_name</SPAN><SPAN style="COLOR: #000000">,role_name)};<IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV>
<P>然后在server.xml中加入：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">Realm&nbsp;</SPAN><SPAN style="COLOR: #ff0000">className</SPAN><SPAN style="COLOR: #0000ff">="org.apache.catalina.realm.JDBCRealm"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;driverName</SPAN><SPAN style="COLOR: #0000ff">="com.mysql.jdbc.Driver"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<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;debug</SPAN><SPAN style="COLOR: #0000ff">="0"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;connectionURL</SPAN><SPAN style="COLOR: #0000ff">="jdbc:mysql://localhost/tomcatusers"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;connectionName</SPAN><SPAN style="COLOR: #0000ff">="roor"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<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;connectonPassword</SPAN><SPAN style="COLOR: #0000ff">=""</SPAN><SPAN style="COLOR: #ff0000">&nbsp;userTable</SPAN><SPAN style="COLOR: #0000ff">="users"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;userNameCol</SPAN><SPAN style="COLOR: #0000ff">="user_name"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<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;userCredCol</SPAN><SPAN style="COLOR: #0000ff">="user_pass"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;userRoleTable</SPAN><SPAN style="COLOR: #0000ff">="user_roles"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;roleNameCol</SPAN><SPAN style="COLOR: #0000ff">="role_name"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV></DIV>
<P></P>
<P></P>
<P><STRONG></P>
<P>DataSource域</STRONG>－和JDBC域很类似，只不过访问数据库的方式不同，这个是使用JNDI DataSource来访问数据库的。<BR>先在web.xml中加入安全约束，在和JDBC域一样新建两张表，然后在server.xml文件的&lt;GlobalNamingResources&gt;元素下添加如下内容：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">Resource&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="jdbc/tomcatusers"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;auth</SPAN><SPAN style="COLOR: #0000ff">="Container"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;type</SPAN><SPAN style="COLOR: #0000ff">="javx.sql.DataSource"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">ResourceParams&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="jdbc/tomcatusers"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff"><FONT color=#000000>&nbsp;&nbsp;&nbsp; </FONT>&lt;</SPAN><SPAN style="COLOR: #800000">parameter</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">name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">factory</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">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; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">value</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">org.apache.commons.dbcp.BasicDataSourceFactory</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">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;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">parameter</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">parameter</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">maxActiove</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">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; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">value</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">100</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">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;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">parameter</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">parameter</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">name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">maxIdle</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">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; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">value</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">30</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">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;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">parameter</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">parameter</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">maxWait</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">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; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">value</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">10000</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">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;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">parameter</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">parameter</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">username</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">value</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">root</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">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;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">parameter</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">parameter</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">password</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">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; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">value</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;/</SPAN><SPAN style="COLOR: #800000">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;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">parameter</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">parameter</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">driverClassName</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">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; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">value</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">com.mysql.jdbc.Driver</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">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;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">parameter</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">parameter</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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">url</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">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; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">value</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">jdbc:mysql://localhost/tomcatusers?autoReconnect=true</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">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;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">parameter</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">ResourceParams</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV>
<P>注意：Tomcat的JNDI资源必须配置在&lt;GlobalNamingResources&gt;元素下，服务器才能找到，否则会出现NameNotFoundException；低于Tomcat5.0.12的版本，即使正确配置了DataSourceRealm，也会出现找不到JNDI DataSource的异常，这个小猫的一个bug；在web.xml中是不需要配置&lt;resource-ref&gt;元素的，因为Web应用并不会访问这个DataSource。<BR>当然server.xml还需要添加和JDBC域几乎相同的代码：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">Realm&nbsp;</SPAN><SPAN style="COLOR: #ff0000">className</SPAN><SPAN style="COLOR: #0000ff">="org.apache.catalina.realm.DataSourceRealm"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; driverName</SPAN><SPAN style="COLOR: #0000ff">="com.mysql.jdbc.Driver"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;debug</SPAN><SPAN style="COLOR: #0000ff">="0"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; connectionURL</SPAN><SPAN style="COLOR: #0000ff">="jdbc:mysql://localhost/tomcatusers"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;connectionName</SPAN><SPAN style="COLOR: #0000ff">="roor"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; connectonPassword</SPAN><SPAN style="COLOR: #0000ff">=""</SPAN><SPAN style="COLOR: #ff0000">&nbsp;userTable</SPAN><SPAN style="COLOR: #0000ff">="users"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;userNameCol</SPAN><SPAN style="COLOR: #0000ff">="user_name"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; userCredCol</SPAN><SPAN style="COLOR: #0000ff">="user_pass"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;userRoleTable</SPAN><SPAN style="COLOR: #0000ff">="user_roles"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;roleNameCol</SPAN><SPAN style="COLOR: #0000ff">="role_name"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV>
<P><STRONG>Tomcat阀<BR></STRONG>由org.apache.Catalina.Value接口定义，能够对Catalina容器接收的HTTP Request进行预处理，是小猫特有的功能，可以加入到3种容器中(Engine、Host、Context)。<BR><BR><STRONG>客户访问日志阀</STRONG>(Access Log Value)－ 能够将可以的Request信息写入到日志中。可以记录页面访问的次数、用户Session活动和用户验证信息等。<BR>例如：&lt;Value className="org.apache.catalina.AccessLogValue" directory="logs" prifix="localhost_access_log" suffix=".txt" pattern="%h%l%u%t%s%r%s%b" resolveHost="true"&gt;<BR>上面的pattern值可以用common，一个默认的值。<BR>pattern属性规定日志的格式和内容：%a－远程IP地址；%A－本地IP地址；%b－发送的字节数，不包括HTTP Header；%h－远程主机名；%H－客户请求所用的协议；%l－"-";%m－请求的方法；%p－接受请求的本地服务器断开；%q－查询字符串；%r－用户请求的第一行内容；%s－响应HTTP Request的状态码；%S－用户Session ID；%t－时间；%u－验证的用户名；%U－请求URL路径；%v－本地服务器名。<BR><BR><STRONG>远程地址过滤器</STRONG>(Remote Address Filter)－根据IP地址决定是否接受客户的请求。<BR>例如：&lt;Value className="org.apache.catalina.RemoteAddrValue" allow="127.0.0.1" deny="127.111.*"/&gt;<BR><BR><STRONG>远程主机过滤器</STRONG>(Remot Host Filter)－根据主机名决定是否接受请求。<BR>&lt;Value className="org.apache.catalina.RemoteHostValue" allow="localhost" deny="monster*"/&gt;<BR><BR><STRONG>客户请求记录器</STRONG>(Request Dumper)－把客户请求的详细信息记录在日志文件中，这里的日志文件是指&lt;Logger&gt;元素。<BR>假定在server.xml中localhost的&lt;Host&gt;元素下已经配置了&lt;Logger&gt;元素：<BR></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">Logger&nbsp;</SPAN><SPAN style="COLOR: #ff0000">className</SPAN><SPAN style="COLOR: #0000ff">="org.apache.catalina.logger.FileLogger"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;directory</SPAN><SPAN style="COLOR: #0000ff">="logs"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;prefix</SPAN><SPAN style="COLOR: #0000ff">="localhos_log."</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; suffix</SPAN><SPAN style="COLOR: #0000ff">=".txt"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;timestamp</SPAN><SPAN style="COLOR: #0000ff">="true"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV>
<P>然后再添加&lt;Value&gt;元素：</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">Value&nbsp;</SPAN><SPAN style="COLOR: #ff0000">className</SPAN><SPAN style="COLOR: #0000ff">="org.apache.catalina.RequestDumperValue"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV>
<P></FONT><FONT color=#808080><BR>参考：《Tomcat与JavaWeb开发技术详解》</FONT></P><img src ="http://www.blogjava.net/pepsixp/aggbug/1261.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pepsixp/" target="_blank">阿姆斯壮</a> 2005-02-16 23:29 <a href="http://www.blogjava.net/pepsixp/archive/2005/02/16/1261.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>