﻿<?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-阿姆斯壮 -随笔分类-基础很重要</title><link>http://www.blogjava.net/pepsixp/category/424.html</link><description>I am strong, I am in Suzhou.</description><language>zh-cn</language><lastBuildDate>Tue, 13 Mar 2007 16:52:51 GMT</lastBuildDate><pubDate>Tue, 13 Mar 2007 16:52:51 GMT</pubDate><ttl>60</ttl><item><title>LDAP 初试</title><link>http://www.blogjava.net/pepsixp/archive/2007/03/12/openldap.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Mon, 12 Mar 2007 15:12:00 GMT</pubDate><guid>http://www.blogjava.net/pepsixp/archive/2007/03/12/openldap.html</guid><wfw:comment>http://www.blogjava.net/pepsixp/comments/101451.html</wfw:comment><comments>http://www.blogjava.net/pepsixp/archive/2007/03/12/openldap.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pepsixp/comments/commentRss/101451.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pepsixp/services/trackbacks/101451.html</trackback:ping><description><![CDATA[
		<p>第一次接触这个东西，有种很混乱的感觉，啃些文档，安装一个再说...</p>
		<ol>
				<li>下载必需的软件：<a href="http://www.oracle.com/technology/software/products/berkeley-db/index.html">Berkeley DB</a> 和 <a href="http://www.openldap.org/software/download/">OpenLDAP</a></li>
				<li>安装Berkeley DB<br /><em>tar -zxvf db-4.5.20.tar.gz<br />cd db-4.5.20/build_unix<br />../dist/configure --prefix=/usr/local/BerkeleyDB.4.5<br />make<br />make intall</em></li>
				<li>安装OpneLDAP <br /><font color="#a9a9a9">这个变量很重要，如果出现错误：<u>Berkeley DB version mismatch</u>，就加上吧~<br /></font><em>export LD_LIBRARY_PATH=/data/install/db-4.5.20/build_unix/.libs()<br /></em><font color="#a9a9a9">据说一定要的<br /></font><em>export CPPFLAGS="-I/usr/local/BerkeleyDB.4.5/include" <br />export LDFLAGS="-L/usr/local/BerkeleyDB.4.5/lib"</em><br /><em>./configure --prefix=/usr/local/openldap --enable-ldbm <br />make depens<br />make<br />make test<br /></em><font color="#a9a9a9">敲完回车，然后去打个盹，醒来后<br /></font><em>make install</em></li>
				<li>启动，进入安装目录的libexec<br /><em>./slapd -d 1</em><br /></li>
		</ol>
		<p>如果一切顺利，运行如下命令会看到点什么的 ^_^，<br /><em>ldapsearch -x -s base (objectclass=*) namingContexts</em></p>
		<b>一些可以做参考的OpenLDAP资料：</b>
		<p>官网：<a href="http://www.openldap.org/">http://www.openldap.org/</a><br />For Win32：<a href="http://lucas.bergmans.us/hacks/openldap/">http://lucas.bergmans.us/hacks/openldap/</a><br />快速指南：<a href="http://www.wzsky.net/html/System/Linux/71587.html">http://www.wzsky.net/html/System/Linux/71587.html</a><br />详细介绍：<a href="http://blog.csdn.net/porcupinefinal/archive/2006/04/03/649598.aspx">http://blog.csdn.net/porcupinefinal/archive/2006/04/03/649598.aspx</a><br />学习笔记：<a href="http://man.lupaworld.com/content/manage/ringkee/openldap.htm">http://man.lupaworld.com/content/manage/ringkee/openldap.htm</a></p>
<img src ="http://www.blogjava.net/pepsixp/aggbug/101451.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-03-12 23:12 <a href="http://www.blogjava.net/pepsixp/archive/2007/03/12/openldap.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>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><item><title>Tom小猫，让我看清你的五脏六腑（一）</title><link>http://www.blogjava.net/pepsixp/archive/2005/02/15/1234.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Tue, 15 Feb 2005 13:13:00 GMT</pubDate><guid>http://www.blogjava.net/pepsixp/archive/2005/02/15/1234.html</guid><wfw:comment>http://www.blogjava.net/pepsixp/comments/1234.html</wfw:comment><comments>http://www.blogjava.net/pepsixp/archive/2005/02/15/1234.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pepsixp/comments/commentRss/1234.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pepsixp/services/trackbacks/1234.html</trackback:ping><description><![CDATA[<P>这只小猫玩了它差不多也有一年多了，还没仔细瞅瞅长个什么样。当它耍性子的时候，常常弄的我手足无措，因为不懂它说出的一大堆乱七八糟的洋话。为了能让它说start就start，说down就down，下面要开始一段我训兽师的经历 ^_^。</P>
<P><STRONG>宠物简介<BR></STRONG>Jakarta Tomcat服务器是一种Servlet/JSP容器，经历了3.x到4.0.x到4.1.x的变迁，现在最新的版本为5.0.x，支持Servlet2.4和JSP2.0规范，从apache网站上下载Tomcat 5，在环境变量中配置一下JAVA_HOME，小猫就能生灵活现的跑起来了。若小猫启动失败，DOS窗口会自动关闭，若运行catalina run命令DOS窗口是不会自动关闭的。</P>
<P>tomcat中有三个放置java库的地方，分别是/server/lib、/shared/lib和/common/lib。<BR>区别：/server/lib － 其中的jar文件只能被tomcat服务器访问。<BR>/shared/lib － 其中的jar文件可以被所有的Web应用访问，但不能被tomcat服务器访问到。<BR>/common/lib － Web服务和tomcat服务器都可以访问的到。</P>
<P><STRONG>server.xml文件解析</STRONG> － 文件位置是&lt;%CATALINA_HOME%&gt;/conf/server.xml</P>
<P><STRONG>配置虚拟主机<BR></STRONG>Host元素代表虚拟主机，在同一个Engine元素下可以配置多个虚拟主机。打开server.xml文件可以发现Engine元素下已经有一个名为localhost的Host元素了，可以在它后面加入下列代码：</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">Host&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="www.myname.com"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;debug</SPAN><SPAN style="COLOR: #0000ff">="0"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;appBase</SPAN><SPAN style="COLOR: #0000ff">="c:\myname"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;unpackWar</SPAN><SPAN style="COLOR: #0000ff">="true"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;autoDeploy</SPAN><SPAN style="COLOR: #0000ff">="true"</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">alias</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">www.myname1.com</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">alias</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">alias</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">www.myname2.com</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">alias</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">Context&nbsp;</SPAN><SPAN style="COLOR: #ff0000">pathh</SPAN><SPAN style="COLOR: #0000ff">="/helloapp"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;docBase</SPAN><SPAN style="COLOR: #0000ff">="helloapp"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;debug</SPAN><SPAN style="COLOR: #0000ff">="0"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;reloadable</SPAN><SPAN style="COLOR: #0000ff">="true"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">Host</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV>
<P><STRONG>Session的使用</STRONG><BR>Session是一种用来跟踪用户状态的机制，那它是怎么实现的呢？Servlet容器通过在客户端浏览器中保存一个Session ID来跟踪Session，调用session.getID()可以看到你的Session ID是多少。如果客户端支持Cookie，就把Session ID作为Cookie保持在浏览器中，现在绝大多数浏览器都会把Cookie功能打开，但如果用户禁止了Cookie呢？Java Servlet API中提出了另外一种机制，Servlet容器可以重写客户requst的URL，把Session ID添加到URL信息中，HttpServletResponse接口提供了这样的方法：public String encodeURL(String url)－先判断如果没有启用Session，例如jsp中&lt;%@ page session="false"%&gt;或执行了session.invalideate()，那么直接返回url，在判断客户端师父支持Cookie，如果不支持，就在url中加入Session ID的信息，然后返回修改后的url。</P>
<P><STRONG>Session的管理<BR></STRONG>当一个sesson开始时，Servlet容器会创建一个HttpSession对象，在某些情况下把这些Httpsession对象从内存中转移到文件系统中或数据库中，需要访问的时候在把它们载入到内存中来。这样做的好处有两点：节约了内存的消耗，当web服务器产生故障时，还可以从文件系统或数据库中恢复Session的数据。<BR>对于Session的管理，小猫提供了两个实现类：org.apache.catalina.session.StandardManager和org.apache.catalina.session.PersistentManager。<BR><STRONG>StandardManager</STRONG> －是默认的方法，当Tomcat服务器重启或重载的时候，会把Session对象保存到<BR>&lt;%CATALINA_HOME%&gt;/work/Catalina/honstname/applicatonname/SESSIONS.ser(默认值)文件中，每个对象对应一个文件，以Session ID为文件名，例如：</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">Context&nbsp;</SPAN><SPAN style="COLOR: #ff0000">path</SPAN><SPAN style="COLOR: #0000ff">="/helloapp"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;docBase</SPAN><SPAN style="COLOR: #0000ff">="helloapp"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;debug</SPAN><SPAN style="COLOR: #0000ff">="0"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;reloadable</SPAN><SPAN style="COLOR: #0000ff">="true"</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">Manager&nbsp;</SPAN><SPAN style="COLOR: #ff0000">className</SPAN><SPAN style="COLOR: #0000ff">="org.apache.catalina.session.StandardManager"</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; maxActiveSessions<FONT color=#0000ff>="-1"</FONT> checkInterval<FONT color=#0000ff>="60"</FONT></SPAN><SPAN style="COLOR: #ff0000">&nbsp;<FONT color=#0000ff>/</FONT></SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">Context</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>参数说明：checkInterval－检查session是否过期的时间间隔，以秒为单位，缺省值是60秒；<BR>maxActiveSessions－可处于活动状态的session数。<BR><BR><STRONG>PersistentManager</STRONG> －提供了更加灵活的管理方式，具有容错能力，可以及时把Session备份到Session Store中，可以控制内存中Session的数量。<BR>小猫还提供了实现<STRONG>持久化Session Store</STRONG>的接口，org.apache.catalina.Store，目前提供了两个具体实现类：org.apache.catalina.FileStore和org.apache.catalina.JDBCStore。<BR>server.xml中的配置File Store －</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">Context&nbsp;</SPAN><SPAN style="COLOR: #ff0000">path</SPAN><SPAN style="COLOR: #0000ff">="/helloapp"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;docBase</SPAN><SPAN style="COLOR: #0000ff">="helloapp"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;debug</SPAN><SPAN style="COLOR: #0000ff">="0"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;reloadable</SPAN><SPAN style="COLOR: #0000ff">="true"</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">Manager&nbsp;</SPAN><SPAN style="COLOR: #ff0000">className</SPAN><SPAN style="COLOR: #0000ff">="org.apache.catalina.session.PersistentManager"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;debug</SPAN><SPAN style="COLOR: #0000ff">="0"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;saveOnRestart</SPAN><SPAN style="COLOR: #0000ff">="true"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; maxActiveSessions</SPAN><SPAN style="COLOR: #0000ff">="-1"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;minIdleSwap</SPAN><SPAN style="COLOR: #0000ff">="-1"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;maxIdleSwap</SPAN><SPAN style="COLOR: #0000ff">="-1"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;maxIdleBackup</SPAN><SPAN style="COLOR: #0000ff">="-1"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</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">Store&nbsp;</SPAN><SPAN style="COLOR: #ff0000">className</SPAN><SPAN style="COLOR: #0000ff">="org.apache.catalina.session.FileStore"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;directory</SPAN><SPAN style="COLOR: #0000ff">="mydir"</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">Manager</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">Context</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>参数说明：saveOnRestart－服务器关闭时，是否将所有的session保存到文件中；<BR>maxActiveSessions－可处于活动状态的session数；<BR>minIdleSwap/maxIdleSwap－session处于不活动状态最短/长时间(s)，sesson对象转移到File Store中；<BR>maxIdleBackup－超过这一时间，将session备份。(－1表示没有限制)<BR><BR><STRONG>JDBCStore配置的区别：</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><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">Store&nbsp;</SPAN><SPAN style="COLOR: #ff0000">calssName</SPAN><SPAN style="COLOR: #0000ff">="org.apache.catalina.JDBCStore"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;driverName</SPAN><SPAN style="COLOR: #0000ff">="com.mysql.jdbc.Driver"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR>&nbsp;&nbsp;&nbsp; connectionURL</SPAN><SPAN style="COLOR: #0000ff">="jdbc:mysql://localhost/tomsessionDB?user=root&amp;password="</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR>&nbsp;&nbsp;&nbsp; sessionTable</SPAN><SPAN style="COLOR: #0000ff">="tomcat_session"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;sessionIdCol</SPAN><SPAN style="COLOR: #0000ff">="session_id"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;sessionDataCol</SPAN><SPAN style="COLOR: #0000ff">="session_data"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR>&nbsp;&nbsp;&nbsp; sessionValidCol</SPAN><SPAN style="COLOR: #0000ff">="session_valid"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;sessionMaxInactiveCol</SPAN><SPAN style="COLOR: #0000ff">="max_inactive"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR>&nbsp;&nbsp;&nbsp; sessionLastAccessedCol</SPAN><SPAN style="COLOR: #0000ff">="last_access"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;sessionAppCol</SPAN><SPAN style="COLOR: #0000ff">="app_name"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;checkInterval</SPAN><SPAN style="COLOR: #0000ff">="60"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;debug</SPAN><SPAN style="COLOR: #0000ff">="99"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><STRONG><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></STRONG></SPAN></DIV></DIV>
<P><STRONG>Session失效时间的设定<BR></STRONG>在web.xml文件中,位于&lt;servlet-mapping&gt;和&lt;welcome-file-list&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">session-config</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff"><FONT color=#000000>&nbsp;&nbsp;&nbsp; </FONT>&lt;</SPAN><SPAN style="COLOR: #800000">session-timeout</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">60</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">session-timeout</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">session-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><STRONG>Tomcat的admin平台和manager平台</STRONG><BR>这是Tomcat中自带的两个Web应用，位于&lt;%CATALINA_HOME%&gt;/server/webapps/admin(manager)，访问地址是http://localhsot:8080/admin(manager)。要访问这两个Web应用，需要在<BR>&lt;%CATALINA_HOME%&gt;/conf/tomcat-users.xml中添加如下内容：<BR>&lt;user username="admin" password="1234" role="admin"/&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //对应admin Web应用<BR>&lt;user username="manager" password="1234" role="manager"/&gt;&nbsp;&nbsp; //对应manager Web应用<BR><BR><STRONG>admin平台</STRONG>把所有可配置的信息分为三类：Tomcat Server、Resources、User Definition。<BR>Tomcat Server－相当于server.xml中的&lt;Server&gt;元素及其子元素，&lt;Service&gt;、&lt;Host&gt;、&lt;Context&gt;、&lt;Resources&gt;、&lt;Date Source&gt;。<BR>Resources－相当于server.xml中的&lt;GlobalNamingResources&gt;，共有四种资源：Date Source(JNDI数据源)、Mail Sessioin(JNDI Mail Session资源)、Environment Entry(环境变量)、User Database(安全域中的用户数据库)。<BR>User Definition－与tomcat-users.xml相对应。<BR><BR><STRONG>manager平台</STRONG>－列出来所有Web应用和状态，并提供了Start、Stop、Reload、 Undeploy命令，还可以发布<BR>&lt;%CATALINA_HOME%&gt;/webapps目录下的Web应用或系统文件任意位置的WAR文件。</P>
<P><BR><FONT color=#808080>参考：《Tomcat与JavaWeb开发技术详解》</FONT></P><img src ="http://www.blogjava.net/pepsixp/aggbug/1234.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-15 21:13 <a href="http://www.blogjava.net/pepsixp/archive/2005/02/15/1234.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>