﻿<?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-★yesjoy★-文章分类-Structs学习</title><link>http://www.blogjava.net/yesjoy/category/7478.html</link><description>&lt;font color="red"&gt;★&lt;/font&gt;&lt;font color="blue"&gt;总在爬山 所以艰辛;总在寻梦 所以苦痛&lt;/font&gt;&lt;font color="red"&gt;★&lt;/font&gt;</description><language>zh-cn</language><lastBuildDate>Tue, 07 Sep 2010 21:47:33 GMT</lastBuildDate><pubDate>Tue, 07 Sep 2010 21:47:33 GMT</pubDate><ttl>60</ttl><item><title>Struts中Logic逻辑标签的作用及用法</title><link>http://www.blogjava.net/yesjoy/articles/110695.html</link><dc:creator>★yesjoy★</dc:creator><author>★yesjoy★</author><pubDate>Sat, 14 Apr 2007 13:07:00 GMT</pubDate><guid>http://www.blogjava.net/yesjoy/articles/110695.html</guid><wfw:comment>http://www.blogjava.net/yesjoy/comments/110695.html</wfw:comment><comments>http://www.blogjava.net/yesjoy/articles/110695.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yesjoy/comments/commentRss/110695.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yesjoy/services/trackbacks/110695.html</trackback:ping><description><![CDATA[<div class=tit>Struts中Logic逻辑标签的作用及用法</div>
<div class=date>2006年10月18日 星期三 21:34</div>
<table style="TABLE-LAYOUT: fixed">
    <tbody>
        <tr>
            <td>
            <div class=cnt><font style="BACKGROUND-COLOR: rgb(255,255,153)" color=#ff0000>Terry原创，转载请说明作者及出处<br><br></font><br>Logic标签大部分的功能是对属性值进行判断，相等后就可以进行设置内容<br><br style="BACKGROUND-COLOR: rgb(51,102,255)"><font size=3><strong><u><font style="BACKGROUND-COLOR: rgb(255,255,255)" color=#000000>数值比较标签集</font></u></strong></font><br><br><span style="BACKGROUND-COLOR: rgb(255,255,255)">&lt;logic:equal name="questionlist" property="queLevel" value="1"&gt;简单&lt;/logic:equal&gt;</span><br><br>比较变量是否不等于指定的常量：<br><br><span style="BACKGROUND-COLOR: rgb(255,255,255)">&lt;logic:notEqual name="questionlist" property="queLevel" value="1"&gt;简单&lt;/logic:notEqual&gt;</span><br><br>比较变量是否大于或等于指定的数值：<br><br style="BACKGROUND-COLOR: rgb(255,255,153)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">&lt;logic:greaterEqual/&gt;</span><br><br>比较变量是否大于指定的数值：<br><br><span style="BACKGROUND-COLOR: rgb(255,255,255)">&lt;logic:greaterThan/&gt;</span><br><br>比较变量是否小于或等于指定的数值：<br><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">&lt;logic:lessEqual/&gt;</span><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">比较变量是否小于指定的数值：</span><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">&lt;logic:lessThan/&gt;</span><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">以上六个标签都是用于比较数值的标签</span><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br><br><br style="BACKGROUND-COLOR: rgb(51,102,255)"><font size=3><u><strong><span style="BACKGROUND-COLOR: rgb(255,255,255)">字符串比较的标签：</span></strong></u></font><br><br><br><span style="BACKGROUND-COLOR: rgb(255,255,255)">判断变量中是否包含指定的字符串常量</span><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">&lt;logic:match name="" value="指定的字符串常量"&gt;</span><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">判断变量中是否不包含指定的字符串常量</span><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">&lt;logic:notMatch name="" value="指定的字符串常量"&gt;</span><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">这两个标签中有一个location属性，其值有二：start，end。说明了指定的字符串是在变量的起始位置，还是变量字符串的结尾位置，如果不指定，指定的字符串可以出现在变量字符串的任意位置</span><br><br><br><br><font size=3><u><strong><span style="BACKGROUND-COLOR: rgb(255,255,255)">判断指定内容是否存在的&lt;logic&gt;标签</span></strong></u></font><br><br><br><span style="BACKGROUND-COLOR: rgb(255,255,255)">判断变量内容是否为空</span><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">&lt;logic:empty&gt;</span><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">判断变量内容是否不为空</span><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">&lt;logic:notEmpty&gt;</span><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">判断指定的对象是否存在</span><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">&lt;logic:present name="对象名" property="子对象名"&gt;</span><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">判断指定的对象是否不存在</span><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">&lt;logic:notPresent name="对象名" property="子对象名"&gt;</span><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><font size=3><u><strong><span style="BACKGROUND-COLOR: rgb(255,255,255)">进行循环遍历的Logic标签</span></strong></u></font><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">&lt;logic:iterate name="requst或session里存的集合对象" id="生成的对象名字，可给bean:write调用" indexId="循环数索引值，从0开始" length="说明只需要从集合中取出多少条数据" offset="循环的起始位置，从0开始"&gt;</span><br><br><font size=3><u><strong><br>进行请求转发，或者页面重定向的Logic标签</strong></u></font> <br><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">&lt;logic:forward name="在Struts-Config.XML文件中定义的global-forwards的对象名称"&gt;</span><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">&lt;logic:forward name="QuestionEdit"&gt;</span><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">页面重定向；它的作用在于在浏览器的地址栏显示的时当前页面的地址，但是重定向后页面内容会改变，但地址栏的内容不变，这样可以达到隐藏页面地址的效果</span><br style="BACKGROUND-COLOR: rgb(255,255,255)"><br style="BACKGROUND-COLOR: rgb(255,255,255)"><span style="BACKGROUND-COLOR: rgb(255,255,255)">&lt;logic:redirect href="网页地址"&gt;</span></div>
            </td>
        </tr>
    </tbody>
</table>
<img src ="http://www.blogjava.net/yesjoy/aggbug/110695.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yesjoy/" target="_blank">★yesjoy★</a> 2007-04-14 21:07 <a href="http://www.blogjava.net/yesjoy/articles/110695.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>struts框架bean,html,logic标签手册 </title><link>http://www.blogjava.net/yesjoy/articles/110694.html</link><dc:creator>★yesjoy★</dc:creator><author>★yesjoy★</author><pubDate>Sat, 14 Apr 2007 13:03:00 GMT</pubDate><guid>http://www.blogjava.net/yesjoy/articles/110694.html</guid><wfw:comment>http://www.blogjava.net/yesjoy/comments/110694.html</wfw:comment><comments>http://www.blogjava.net/yesjoy/articles/110694.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yesjoy/comments/commentRss/110694.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yesjoy/services/trackbacks/110694.html</trackback:ping><description><![CDATA[<div>（转自solol.org）<br>目录：<br>bean:cookie<br>bean:define <br>bean:header <br>bean:include <br>bean:message <br>bean:page <br>bean:parameter <br>bean:resource <br>bean:size <br>bean:struts <br>bean:write <br>html:base <br>html:cancel <br>html:select <br>html:checkbox <br>html:radio <br>html:multibox <br>html:link <br>html:errors <br>html:javascript <br>html:xhtml <br>logic:iterate <br>logic:present <br>logic:messagesPresent <br>logic:empty <br>logic:match <br>logic:equal <br>logic:forward <br>总结 <br>参考资料 <br>关于作者<br><br>正文：<a href="http://www.solol.org/technologic/java/j-struts/#d3e77"><br></a></div>
<div>Struts是Apache Jakarta的一个著名的开源项目，目标是为构建基于Java的web应用程序提供一个框架。</div>
<p>Struts提供了非常多的标签，依据功能和使用习惯的不同被分到了五个标签库中:</p>
<ul>
    <li>Bean Tags:该标签库包含的标签可以用来创建bean、访问bean和访问bean的属性。同时提供了依据cookies、headers和parameters的值创建相关bean的能力。
    <li>HTML Tags:该标签库包含的标签可以用来创建Struts输入表单。
    <li>Logic Tags:该标签库包含的标签可以用来进行逻辑判断、集合迭代和流程控制。
    <li>Nested Tags:该标签库建立在前三个标签库的基础上，具有前三个标签库的所有功能，只是允许标签间的嵌套。
    <li>Tiles Tags:该标签库包含的标签可以用来创建tiles样式的页面。 </li>
</ul>
<p>这篇指南主要介绍前三个标签库中的标签。如果您对后两类标签也感兴趣可以查阅<a href="http://www.solol.org/technologic/java/j-struts/#resource"><u><font color=#0000ff>参考资料</font></u></a>中的Struts的用户指南。 </p>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e77>bean:cookie</a> </h2>
<p>cookie最早是由Netscape公司提出来的，用来存储客户的少量状态信息。如果您对cookie的具体细节感兴趣可以查阅<a href="http://www.solol.org/technologic/java/j-struts/#resource"><u><font color=#0000ff>参考资料</font></u></a>中的cookie spec。 </p>
<p>bean:cookie标签取回请求中名称为name的cookie的值。如果没有指定multiple属性则依据刚取回的值创建一个Cookie类型的bean。如果指定了multiple属性则依据刚取回的值创建一个Cookie[]类型的数组。然后用id属性值将Cookie或Cookie[]绑定到page作用域中(这种绑定是为了其它标签能够使用该值)，并创建对应的scripting变量(这种变量是为了JSP脚本能够使用该值)。</p>
<p>下面的代码片段示例了如何使用bean:cookie标签读取名为JSESSIONID的cookie的值，并且使用了两种方式进行了输出：</p>
<pre>&lt;logic:present cookie="JSESSIONID"&gt;
&lt;bean:cookie id="jSession" name="JSESSIONID"/&gt;
&lt;!-- 其它标签通过绑定到page作用域中的属性使用该值 --&gt;
这个cookie的名称是&lt;bean:write name="jSession" property="name"/&gt;，
值为&lt;bean:write name="jSession" property="value"/&gt;。&lt;br/&gt;
&lt;!-- JSP脚本通过scripting变量使用该值 --&gt;
&lt;%
String name = jSession.getName();
String value = jSession.getValue();
out.println("这个cookie的名称是"+name+"，值为"+value+"。
&lt;br/&gt;");
%&gt;
&lt;/logic:present&gt;
</pre>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e98>bean:define</a> </h2>
<p>bean:define标签在toScope(如果没有指定值就使用page作用域)指定的作用域中创建一个新属性，同时创建一个scripting变量。我们可以通过id值使用它们。新创建的属性可以由其它标签使用，而新创建的scripting变量可以由JSP脚本使用。</p>
<p>我们可以使用三种方式为新创建的属性和scripting变量赋值： </p>
<ul>
    <li>通过该标签的name、property和scope取回值，并且保持类型的一致性，除非取回的值为Java的原始类型，这时会使用适合的包装器类对这些值进行包装。
    <li>通过该标签的value指定值，这时新创建的属性和scripting变量的类型为java.lang.String。
    <li>通过在该标签的体中嵌入值，这时新创建的属性和scripting变量的类型为java.lang.String。 </li>
</ul>
<p>&nbsp;</p>
<p>下面的代码片段示例了如何使用bean:define标签创建新属性values和新scripting变量values，它将listForm中persons的值取出来赋给values:</p>
<pre>&lt;bean:define id="values" name="listForm" property = "persons"
type="java.util.List"/&gt;
</pre>
<p>下面给出ListForm的代码片段以帮助您更好的理解，其中Person是一个只有id和name两个属性的简单bean：</p>
<pre>public class ListForm extends ActionForm {
private List&lt;Person&gt; persons = null;
public List&lt;Person&gt; getPersons() {
return persons;
}
public void setPersons(List&lt;Person&gt; persons) {
this.persons = persons;
}
public void reset(ActionMapping mapping,
HttpServletRequest request) {
persons = null;
}
}
</pre>
<p>下面的代码片段示例了logic:iterate标签如何使用bean:define标签创建的新属性values:</p>
<pre>&lt;logic:iterate id="person" name="values"&gt;
&lt;bean:write name="person" property="id"/&gt;&lt;br/&gt;
&lt;/logic:iterate&gt;
</pre>
<p>下面的代码片段示例了JSP脚本如何使用bean:define标签创建的新scripting变量values:</p>
<pre>&lt;%
Person p = new Person();
for(int i=0;i&lt;values.size();i++){
p = (Person)values.get(i);
out.println(p.getId());
out.println("&lt;br/&gt;");
}
%&gt;
</pre>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e148>bean:header</a> </h2>
<p>bean:header标签取回请求中名称为name的header的值。如果没有指定multiple属性则依据刚取回的值创建一个String类型的bean。如果指定了multiple属性则依据刚取回的值创建一个String[]类型的数组。然后用id属性值将String或String[]绑定到page作用域中(这种绑定是为了其它标签能够使用该值)，并创建对应的scripting变量(这种变量是为了JSP脚本能够使用该值)。</p>
<p>下面是我的浏览器发送的header的内容，这些内容和浏览器有关，因此您的浏览器发送的内容可能和下面列出的不同。不过这没有关系，因为要理解bean:header标签您只要对这些内容有一个大概的认识就足够了。</p>
<pre>accept: */*
accept-language: zh-cn
accept-encoding: gzip, deflate
user-agent: Mozilla/4.0 (compatible; MSIE 6.0; //应该在同一行
Windows NT 5.1; SV1; .NET CLR 1.1.4322)
host: localhost:8080
connection: Keep-Alive
</pre>
<p>下面的代码片段示例了如何使用bean:header标签读取名为User-Agent的header的值，并且使用了两种方式进行了输出：</p>
<pre>&lt;logic:present header="User-Agent"&gt;
&lt;!-- 其它标签通过绑定到page作用域中的属性使用该值 --&gt;
您的浏览器是&lt;bean:header id="userAgent" name="User-Agent"/&gt;
&lt;bean:write name="userAgent"/&gt;。&lt;br/&gt;
&lt;!-- JSP脚本通过scripting变量使用该值 --&gt;
&lt;%
out.println("您的浏览器是"+userAgent+"。&lt;br/&gt;");
%&gt;
&lt;/logic:present&gt;
</pre>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e169>bean:include</a> </h2>
<p>bean:include标签对指定url(由forward、href或page确定)处的资源做一个请求，将响应数据作为一个String类型的bean绑定到page作用域，同时创建一个scripting变量。我们可以通过id值访问它们。</p>
<p>下面的代码片段示例了bean:include标签的用法，其中include.txt文件包含要include的内容，然后将这些内容输出:</p>
<pre>&lt;bean:include id="value" page="/include.txt"/&gt;
&lt;!-- 其它标签通过绑定到page作用域中的属性使用该值 --&gt;
&lt;bean:write name="value"/&gt;&lt;br/&gt;
&lt;!-- JSP脚本通过scripting变量使用该值 --&gt;
&lt;%
out.println(value);
%&gt;
</pre>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e184>bean:message</a> </h2>
<p>bean:message标签用来从指定的locale中取回国际化的消息并输出，在这个过程中我们还可以传递五个以内的参数。message key可以通过key直接指定，也可以通过name和property间接的指定。</p>
<p>bean:message标签有两种指定message key的方式，一是通过key属性直接指定；二是通过name和property属性间接的指定，其中message key是在message resources文件中定义的。</p>
<p>我们可以在struts-config.xml文件中使用&lt;message-resources&gt;来设置message resources文件。</p>
<p>为了介绍该标签我使用了三个message resources文件，三个文件的名字分别为Resources.properties、Resources_en.properties和Resources_zh.properties。在struts-config.xml文件中的设置(这里不用设置三个，struts会依据locale自动找到对应的文件)如下：</p>
<pre>&lt;message-resources parameter="Resources" /&gt;
</pre>
<p>三个message resources文件中定义的message key为：</p>
<pre>&lt;!-- Resources.properties --&gt;
resource=Resources.properties.
from=Resources.properties.
&lt;!-- Resources_en.properties --&gt;
from=Resources_en.properties.
&lt;!-- Resources_zh.properties
因为文件的编码被限制为ISO8859所以要有汉字必须用jdk的native2ascii提前转换
--&gt;
from=Resources_zh.properties.
</pre>
<p>下面的代码片段示例了bean:message标签的用法:</p>
<pre>&lt;bean:message key="from"/&gt;&lt;br/&gt;
&lt;bean:message key="resource"/&gt;&lt;br/&gt;
&lt;html:link action="/locale?language=en"&gt;English&lt;/html:link&gt;
&lt;html:link action="/locale?language=zh"&gt;Chinese&lt;/html:link&gt;
</pre>
<p>上面的代码中含有改变locale的两个html:link标签，要使它们工作您的struts-config.xml文件中必须含有下面定义的form和action:</p>
<pre>&lt;form-bean name="localeForm"
type="org.apache.struts.action.DynaActionForm"&gt;
&lt;form-property name="language" type="java.lang.String" /&gt;
&lt;form-property name="country" type="java.lang.String" /&gt;
&lt;!--action成功后要跳到那里--&gt;
&lt;form-property name="page"  type="java.lang.String"
initial="/message.jsp"/&gt;
&lt;/form-bean&gt;
&lt;action path="/locale" type="org.apache.struts.actions.LocaleAction"
name="localeForm" scope="request"&gt;
&lt;/action&gt;
</pre>
<p>在不同的locale下我们得到了如下的两个结果：</p>
<pre>在locale为zh时的结果：
Resources_zh.properties.
Resources.properties.
在locale为en时的结果：
Resources_en.properties.
Resources.properties.
</pre>
<p>让我们来看一下在locale为zh时如何得到的是上面的结果。因为locale为zh所以&lt;bean:message key="from"/&gt;&lt;br/&gt;先找Resources_zh.properties这个文件从中得到form键的值。而&lt;bean:message key="resource"/&gt;&lt;br/&gt;也会先找Resources_zh.properties这个文件但这次没有找到resource键，这时Struts会到Resources.properties这个文件中找，很幸运这里找到了。如果还没有找到，或message resource文件不存在就会抛出异常。当locale为en时类似，您可以自己试试。 </p>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e235>bean:page</a> </h2>
<p>bean:page标签将页上下文中的application、config、request、response 或 session取出，然后用id属性值将它们绑定到page作用域中(这种绑定是为了其它标签能够使用该值)，并创建对应的scripting变量(这种变量是为了JSP脚本能够使用该值)。</p>
<p>下面的代码片段示例了bean:page标签取出response，然后使用bean:write标签将response的characterEncoding和contentType属性输出：</p>
<pre>&lt;bean:page id="res" property="response"/&gt;
&lt;!-- 其它标签通过绑定到page作用域中的属性使用该值 --&gt;
&lt;bean:write name="res" property="characterEncoding"/&gt;&lt;br/&gt;
&lt;bean:write name="res" property="contentType"/&gt;&lt;br/&gt;
&lt;!-- JSP脚本通过scripting变量使用该值 --&gt;
&lt;%
String characterEncoding = res.getCharacterEncoding();
String contentType = res.getContentType();
out.println(characterEncoding+"&lt;br/&gt;");
out.println(contentType+"&lt;br/&gt;");
%&gt;
</pre>
<p>您可以用和上面类似的代码访问application、config、request 或 session中的任何一个对象。</p>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e253>bean:parameter</a> </h2>
<p>bean:parameter标签取回请求中的参数值。如果没有指定multiple属性则依据刚取回的值创建一个String类型的bean。如果指定了multiple属性则依据刚取回的值创建一个String[]类型的数组。然后用id属性值将String或String[]绑定到page作用域中(这种绑定是为了其它标签能够使用该值)，并创建对应的scripting变量(这种变量是为了JSP脚本能够使用该值)。</p>
<p>下面的两个代码片段使用相同的url传递参数，url的形式为http://127.0.0.1:8080/struts-demo/parameter.jsp?param=1&amp;param=2&amp;param=3。前面的代码片段中没有指定multiple属性，因此p是String类型而且仅仅读取了参数的第一个值。后面的代码片段中指定了multiple属性的值，因此ps是String[]类型的包含所有参数的值。</p>
<pre>&lt;bean:parameter id="p" name="param"/&gt;
&lt;bean:write name="p"/&gt;
</pre>
<pre>&lt;bean:parameter id="ps" multiple="true" name="param"/&gt;
&lt;logic:iterate id="p" name="ps"&gt;
&lt;bean:write name="p"/&gt;&lt;br/&gt;
&lt;/logic:iterate&gt;
</pre>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e271>bean:resource</a> </h2>
<p>bean:resource标签取回指定的web应用程序的资源，以InputStream或String的形式保存到page作用域中并且创建scripting变量。采用什么形式取决于标签的input属性，如果指定input则以InputStream的形式保存，如果没有指定input则以String的形式保存。</p>
<p>下面的两个代码片段示例了bean:resource标签，其中resource.txt是要使用的资源文件。前面的代码片段中没有指定input属性，因此以String的形式处理资源文件，bean:write标签输出资源文件的内容。后面的代码片段中指定了input属性的值，因此以InputStream的形式使用资源文件，两个bean:write标签分别输出InputStream对象的实例名(如java.io.ByteArrayInputStream@16dadf9)和类名(如class java.io.ByteArrayInputStream)。 </p>
<pre>&lt;bean:resource id="str" name="/resource.txt"/&gt;
&lt;!-- 其它标签通过绑定到page作用域中的属性使用该值 --&gt;
&lt;bean:write name="str"/&gt;&lt;br/&gt;
&lt;!-- JSP脚本通过scripting变量使用该值 --&gt;
&lt;%
out.println(str+"&lt;br/&gt;");
%&gt;
</pre>
<pre>&lt;bean:resource id="is" input="true" name="/resource.txt"/&gt;
&lt;!-- 其它标签通过绑定到page作用域中的属性使用该值 --&gt;
&lt;bean:write name="is"/&gt;&lt;br/&gt;
&lt;bean:write name="is" property="class"/&gt;
&lt;!-- JSP脚本通过scripting变量使用该值 --&gt;
&lt;%
out.println(is+"&lt;br/&gt;");
out.println(is.getClass()+"&lt;br/&gt;");
%&gt;
</pre>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e290>bean:size</a> </h2>
<p>bean:size标签创建一个java.lang.Integer类型的bean，这个bean的值为该标签指定的Collection或Map中所含元素的个数。 这可以和logic:iterate标签配合使用，因为logic:iterate标签不能得到所叠代的集合的元素的个数，这有时候很不方便。 </p>
<p>下面的代码片段示例了bean:size标签取出persons中还有元素的个数，其中listForm和persons的定义参见bean:define标签部分：</p>
<pre>&lt;logic:notEmpty name="listForm" property = "persons"&gt;
&lt;bean:size id="size" name="listForm" property = "persons"/&gt;
&lt;bean:write name="size"/&gt;
&lt;/logic:notEmpty&gt;
</pre>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e305>bean:struts</a> </h2>
<p>bean:struts标签取回Struts的内部对象formBean、forward或mapping的值，然后用id绑定到page作用域中(这种绑定是为了其它标签能够使用该值)，并创建对应的scripting变量(这种变量是为了JSP脚本能够使用该值)。</p>
<p>下面的代码片段示例了bean:struts标签取出listForm对象，让我们先来看一下listForm的定义在读代码：</p>
<pre>&lt;!-- listForm的定义&lt;form-bean name="listForm"
type="org.solo.struts.form.ListForm" /&gt; --&gt;
&lt;bean:struts id="listFormBean" formBean="listForm"/&gt;
name:&lt;bean:write name="listFormBean" property="name"/&gt;&lt;br/&gt;
type:&lt;bean:write name="listFormBean" property="type"/&gt;&lt;br/&gt;
dynamic:&lt;bean:write name="listFormBean" property="dynamic"/&gt;&lt;br/&gt;
</pre>
<p>上面代码运行的结果为：</p>
<pre>name:listForm
type:org.solo.struts.form.ListForm
dynamic:false
</pre>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e326>bean:write</a> </h2>
<p>bean:write标签将指定的bean的属性值写到当前的JspWriter中，并且可以对输出进行格式化。</p>
<p>下面的代码片段示例了bean:write标签输出User-Agent：</p>
<pre>&lt;logic:present header="User-Agent"&gt;
&lt;bean:header id="header" name="User-Agent"/&gt;
&lt;bean:write name="header"/&gt;
&lt;/logic:present&gt;
</pre>
<p>下面的代码片段示例了bean:write标签格式化输出当前日期，其中now是在DataForm中定义的一个java.util.Date类型的域(值为new Date())，format.date.standard是在资源文件中的一个键(format.date.standard=yyyy-MM-dd)：</p>
<pre>&lt;bean:define id="date" name="dataForm" property="now"/&gt;
&lt;br/&gt;&lt;bean:write name="date"/&gt;
&lt;br/&gt;&lt;bean:write name="date" format="MM/dd/yyyy"/&gt;
&lt;br/&gt;&lt;bean:write name="date" formatKey="format.date.standard"/&gt;
</pre>
<p>上面代码运行的结果为：</p>
<pre>Sun Jun 04 17:04:05 CST 2006
06/04/2006
2006-06-04
</pre>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e355>html:base</a> </h2>
<p>虽然这里的标题是html:base标签，但是这里也是这篇指南要介绍的第一个Struts html标签。因此我想在这里从整体上简单的介绍一下，最后给出一个对照表。其中的绝大多数标签就不一一介绍了，要介绍的也不会在这里介绍，而是将其独立出来以显重要性。</p>
<p>从用户处收集数据是动态web应用非常重要的一个方面，因此构建输入表单也就自然而然的成为struts框架的一个重要内容。Struts html标签库含有创建Struts输入表单的标签，和其它标签库(bean、logic、nested和tiles)中的标签一起协作就可以产生基于html的用户界面。</p>
<p>下面的对照表会使您对Struts html标签库有一个整体的印象：</p>
<p>&nbsp;</p>
<div>图示 1. Struts HTML标签和HTML元素对照表</div>
<img height=755 alt="Struts HTML标签和HTML元素对照表" src="http://www.360doc.com/DownloadImg/13047/360318_1.gif" width=679>
<p>&nbsp;</p>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e378>html:cancel</a> </h2>
<p>html:cancel标签生成一个取消按钮。当点击该按钮后action servlet会绕过相应的form bean的validate()方法，同时将控制权交给相应的action。在该action中可以使用Action.isCancelled(HttpServletRequest)方法判断是否被取消了。如果返回true表示这个action被取消了，否则表示这个action没有被取消。</p>
<p>请注意，如果您修改了html:cancel标签的property属性值，那么struts提供的cancel探测机制就失效了，您自己必须提供类似的机制。</p>
<p>下面是可取消的action的配置文件，注意&lt;set-property property="cancellable" value="true"/&gt;这一行，如果不添加Struts会抛出org.apache.struts.action.InvalidCancelException异常。这是我在完成本指南的过程中发现的唯一向下不兼容的地方。</p>
<pre>&lt;action path="/cancel"
type="org.solo.struts.action.CancelAction" name="cancelForm"
scope="request"&gt;
&lt;set-property property="cancellable" value="true"/&gt;
&lt;forward name="success" path="/cancel.jsp" /&gt;
&lt;/action&gt;
</pre>
<p>下面是html:cancel标签的代码：</p>
<pre>&lt;html:cancel&gt;取消&lt;/html:cancel&gt;
</pre>
<p>下面是对应的action中的代码：</p>
<pre>if(isCancelled(request)){
//action被取消时要做的事情写在这里
return mapping.findForward("cancel");
}else{
//action没有被取消时要做的事情写在这里
return mapping.findForward("success");
}
</pre>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e409>html:select</a> </h2>
<p>html:select标签生成一个select元素。是单选还是多选取决于该标签的multiple属性。如果指定了multiple="true"则为多选，此时对应的属性应该是一个数组。如果没有指定multiple="true"则为单选，此时对应的属性应该是标量。</p>
<p>注意：为了正确的处理没有做任何的选择的情况，在ActionForm中的reset()方法中必须将标量属性设置为默认值而将数组的长度置为0。</p>
<p>另外的一个重要问题就是struts如何生成option元素了，这个任务struts交给了html:option、html:options和html:optionsCollection三个标签。</p>
<p>html:option标签</p>
<p>html:option标签生成一个HTML的option元素。该标签必须嵌在html:select标签中。它的显示文本来自其标签体，也可以来自于资源文件。它的value属性用来指定什么值将要被提交。</p>
<pre>&lt;html:option value="one"&gt;one&lt;/html:option&gt;
&lt;html:option value="two"&gt;two&lt;/html:option&gt;
</pre>
<p>html:options标签</p>
<p>html:options标签生成多个HTML的option元素。该标签必须嵌在html:select标签中。而且工作方式有些特殊，它的name与property属性和其它标签的name与property属性意义不一致，让我们具体看一下它的工作方式。</p>
<ul>
    <li>指定collection属性
    <li>没有指定collection属性 </li>
</ul>
<p>指定collection属性</p>
<p>让我通过示例来介绍在指定collection属性时该标签的工作方式，首先要说明selectForm中的persons和listForm中的persons完全一致。请参见bean:define标签。</p>
<p>下面的代码先利用bean:define标签将selectForm中的persons取到page作用域中，然后html:options标签再依据collection="personCollection"选中这个persons并将其中的每一个对象(Person类型)生成一个option元素。该标签的property="id"表示persons中的对象(Person类型)的id属性将作为option元素的value值。该标签的labelProperty="name"表示persons中的对象(Person类型)的name属性将作为option元素的label值。</p>
<p>当这个select提交时所选择的值将被提交到selectForm(name="selectForm")中的person对象(这是在SelectForm中声明的一个Person类型的域专门用来接收提交的值)的id属性中(property="person.id")。</p>
<pre>&lt;bean:define id="personCollection" name="selectForm"
property="persons"/&gt;
&lt;html:select name="selectForm" property="person.id" size="1"&gt;
&lt;html:options collection="personCollection" property="id"
labelProperty="name"/&gt;
&lt;/html:select&gt;
</pre>
<p>没有指定collection属性</p>
<p>让我通过示例来介绍没有指定collection属性时该标签的工作方式，先来看看ids和names的定义：</p>
<pre>  private List&lt;String&gt; ids = null;
private List&lt;String&gt; names = null;
</pre>
<p>上面的代码来自SelectForm，其中ids是一个String的列表，names也是一个String的列表。我们暂时假定这两个列表含有相同数目的元素。有了这些让我们开始介绍下面的代码。html:options标签用ids中的第i个值作为option元素的value值同时使用names中相同位置的值(第i个值)作为option元素的label值。如果ids比names长那么多出的ids中的值将即作为option的value又作为option的label。如果ids比names短那么多出的names的值会被丢掉。</p>
<p>当这个select提交时所选择的值将被提交到selectForm(name="selectForm")中的person对象(这是在SelectForm中声明的一个Person类型的域专门用来接收提交的值)的id属性中(property="person.id")。</p>
<pre>&lt;html:select name="selectForm" property="person.id" size="1"&gt;
&lt;html:options property="ids" labelProperty="names"/&gt;
&lt;/html:select&gt;
</pre>
<p>html:optionsCollection标签</p>
<p>html:optionsCollection标签生成多个HTML的option元素。该标签必须嵌在html:select标签中。它的功能和html:options标签的相同，但是它的name与property属性和其它标签的name与property属性意义一致，理解起来比较自然。</p>
<p>让我通过示例来介绍html:optionsCollection标签的用法。首先依据name="selectForm"和property="persons"取到selectForm中的persons列表，然后将列表中的对象(Person类型)的id属性作为option元素的value值(value="id")，将列表中的对象(Person类型)的name属性作为option元素的label值(label="name")。</p>
<pre>&lt;html:select name="selectForm" property="person.id" size="1"&gt;
&lt;html:optionsCollection name="selectForm" property="persons"
label="name" value="id"/&gt;
&lt;/html:select&gt;
</pre>
<p>下面是一个多选的示例，虽然示例中使用了html:options标签，但是html:option和html:optionsCollection也能够用来多选。而且您还必须意识到html:option、html:options和html:optionsCollection这三个标签可以同时使用。代码中的personIds是SelectForm中声明的一个String[]类型的数组用来接收提交的多个值。</p>
<pre>&lt;html:select name="selectForm" property="personIds"
multiple="true" size="2"&gt;
&lt;html:options property="ids" labelProperty="names"/&gt;
&lt;/html:select&gt;
</pre>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e504>html:checkbox</a> </h2>
<p>html:check标签生成一个checkbox。这里的value值可以是true，yes或on。如果您要提交其它的值(如某种形式的标识)应该考虑使用html:multibox标签。</p>
<p>注意:为了正确的处理没有选中的checkbox您必须在reset()中设置对应的属性为false。</p>
<p>下面的代码示例了html:checkbox标签的用法，其中CheckboxForm中声明了三个boolean类型的域，如下：</p>
<pre>				<!-- 略掉了get方法(也可以是isXXX形式)和set方法 -->
private boolean one = false;
private boolean two = false;
private boolean three = false;
</pre>
<pre>&lt;html:checkbox name="checkboxForm" property="one"&gt;
One
&lt;/html:checkbox&gt;
&lt;html:checkbox name="checkboxForm" property="two"&gt;
Two
&lt;/html:checkbox&gt;
&lt;html:checkbox name="checkboxForm" property="three"&gt;
Three
&lt;/html:checkbox&gt;
</pre>
<p>如果选中后被提交则相应的属性的值为true。</p>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e531>html:radio</a> </h2>
<p>html:radio标签生成一个radio。主要的用法有两种，下面我们通过代码来示例。</p>
<p>下面的代码示例了html:radio标签的一般用法，如果被提交则选中的radio的value值将被提交到radioForm中的id中。</p>
<pre>&lt;html:radio name="radioForm" property="id" value="00001"&gt;
One
&lt;/html:radio&gt;
&lt;html:radio name="radioForm" property="id" value="00002"&gt;
Two
&lt;/html:radio&gt;
</pre>
<p>下面的代码示例了html:radio标签的典型用法，其中的persons和bean:define标签中的一致，您可以参考bean:define标签。我只介绍这个&lt;html:radio idName="person" property="id" value="id"&gt;，idName指定html:radio要使用的bean(这里为person)，value="id"表示person的id属性将作为radio元素的value值而property="id"表示提交时选中的radio的值将被提交给radioForm中的id属性。 </p>
<pre>&lt;logic:notEmpty name="radioForm" property="persons"&gt;
&lt;logic:iterate id="person" name="radioForm" property="persons"&gt;
&lt;html:radio idName="person" property="id" value="id"&gt;
&lt;bean:write name="person" property="name"/&gt;
&lt;/html:radio&gt;
&lt;/logic:iterate&gt;
&lt;/logic:notEmpty&gt;
</pre>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e552>html:multibox</a> </h2>
<p>html:multibox标签生成多个checkbox。当您要使用大量的checkbox时使用这个标签非常方便，可以使您避免在ActionForm中声明大量的boolean类型的变量，带之以一个数组就行了。</p>
<p>注意:为了正确的处理没有选中的checkbox您必须在reset()中设置数组的长度为0。</p>
<p>下面的代码示例了html:multibox标签的一般用法，如果被提交则选中的所有checkbox的value值将被提交到multiboxForm中的selectedItems中，这是一个String[]数组。</p>
<pre>&lt;html:multibox name="multiboxForm" property="selectedItems"
value="00001"/&gt;
&lt;html:multibox name="multiboxForm" property="selectedItems"
value="00002"/&gt;
</pre>
<p>下面的代码示例了html:multibox标签的典型用法：</p>
<pre>&lt;logic:iterate id="person" name="multiboxForm" property="persons"&gt;
&lt;html:multibox property="selectedItems"&gt;
&lt;bean:write name="person" property="id"/&gt;
&lt;/html:multibox&gt;
&lt;bean:write name="person" property="name"/&gt;
&lt;/logic:iterate&gt;
</pre>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e578>html:link</a> </h2>
<p>html:link标签生成一个锚点(&lt;a&gt;)元素。我从html:link标签如何构造基本url和如何构造query参数两个方面来介绍这个标签。</p>
<p>构造基本url是依据该标签的如下四个属性进行的，这四个属性一次只能出现一个。让我们看看它们： </p>
<ul>
    <li>forward，指定一个全局ActionForward的名称。另外如果forward是module相关的则该forward必须指向一个action而不能是一个页面。
    <li>action，指定一个Action的名称。
    <li>href，struts会直接使用这个值而不会对其进行任何处理。
    <li>page，指定一个页面的路径，必须以/开始。 </li>
</ul>
<p>&nbsp;</p>
<p>构造query参数，下面列举了可能的形式，其中baseurl只是一个占位符： </p>
<ul>
    <li>baseurl?p=00001(单参单值)
    <li>baseurl?p1=00001&amp;p2=00002&amp;p3=00003(多参单值)
    <li>baseurl?p=00001&amp;p=00002&amp;p=00003(单参多值)
    <li>baseurl?p1=00001&amp;p2=00002&amp;p=00001&amp;p=00002&amp;p=00003(混合) </li>
</ul>
<p>&nbsp;</p>
<p>下面我们以代码示例来说明每一种html:link的用法，首先让我们花点时间看看相关action中的代码：</p>
<pre>&lt;!-- 下面所有代码的数据都是在这里构造的 --&gt;
public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) {
DataForm dataForm = (DataForm) form;
dataForm.setParam("00001");
HashMap paramSingleMap = new HashMap();
paramSingleMap.put("p1","00001");
paramSingleMap.put("p2","00002");
paramSingleMap.put("p3","00003");
dataForm.setParamSingleMap(paramSingleMap);
HashMap paramMultiMap = new HashMap();
paramMultiMap.put("p",new String[]{"00001","00002","00003"});
dataForm.setParamMultiMap(paramMultiMap);
HashMap paramSMMap = new HashMap();
paramSMMap.put("p1","00001");
paramSMMap.put("p2","00002");
paramSMMap.put("p",new String[]{"00001","00002","00003"});
dataForm.setParamSMMap(paramSMMap);
List&lt;Person&gt; persons = new ArrayList&lt;Person&gt;();
Person person1 = new Person();
person1.setId("00001");
person1.setName("赵辰");
Person person2 = new Person();
person2.setId("00002");
person2.setName("李为芳");
Person person3 = new Person();
person3.setId("00003");
person3.setName("王微");
persons.add(person1);
persons.add(person2);
persons.add(person3);
dataForm.setPersons(persons);
return mapping.findForward("success");
}
</pre>
<pre>&lt;!-- 这用来设置一个位置 --&gt;
&lt;html:link linkName="top"/&gt;
&lt;!-- 这用来定位到上面的那个位置 --&gt;
&lt;html:link page="/link.do" anchor="top"&gt;Go Top&lt;/html:link&gt;
</pre>
<pre>&lt;html:link page="/link.do" paramId="p" paramName="dataForm"
paramProperty="param"&gt;
单参单值
&lt;/html:link&gt;&lt;br/&gt;
&lt;html:link page="/link.do" name="dataForm" property="paramSingleMap"&gt;
多参单值
&lt;/html:link&gt;&lt;br/&gt;
&lt;html:link page="/link.do" name="dataForm" property="paramMultiMap"&gt;
单参多值
&lt;/html:link&gt;&lt;br/&gt;
&lt;html:link page="/link.do" name="dataForm" property="paramSMMap"&gt;
混合
&lt;/html:link&gt;
</pre>
<p>下面的代码示例了html:link标签的indexed属性和indexId属性的用法，这两个属性只有html:link标签嵌套在logic:iterate标签中时才可用。</p>
<pre>&lt;logic:iterate id="person" name="dataForm" property="persons"&gt;
&lt;html:link action="/link.do" paramId="person" paramName="person"
paramProperty="id" indexed="true" indexId="number"&gt;
person
&lt;/html:link&gt;
&lt;br/&gt;
&lt;/logic:iterate&gt;
&lt;!-- 下面是上面代码的运行结果(产生的html)
&lt;a href="/struts-demo/link.do?person=00001&amp;number=0"&gt;赵辰&lt;/a&gt;&lt;br/&gt;
&lt;a href="/struts-demo/link.do?person=00002&amp;number=1"&gt;李为芳&lt;/a&gt;&lt;br/&gt;
&lt;a href="/struts-demo/link.do?person=00003&amp;number=2"&gt;王微&lt;/a&gt;&lt;br/&gt;
其中的number是由indexId="number"确定的，而该参数的值为元素在集合中的位置。
--&gt;
</pre>
<p>html:rewrite标签和html:link标签类似只是不生成锚点(&lt;a&gt;)，而是简单的输出字符串。</p>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e645>html:errors</a> </h2>
<p>html:errors标签和html:messages标签的功能相似，所以我们放到一起来介绍。</p>
<p>html:errors标签将由name属性指定的ActionMessages、ActionErrors、String和String[]直接输出到页面中。</p>
<p>html:messages标签将用由name属性(注意message属性值对它的影响)指定的ActionMessages、ActionErrors、String和String[]创建一个新的属性和scripting变量，使用id属性值作为名称。</p>
<p>html:errors标签和html:messages标签的property属性是用来为errors和messages分类的。我们可以给这两个标签指定property属性，以便只显示某一类的错误或消息。</p>
<p>在资源文件增加了如下的内容：</p>
<pre># -- standard errors --
errors.header=&lt;ul&gt;
errors.prefix=&lt;li&gt;
errors.suffix=&lt;/li&gt;
errors.footer=&lt;/ul&gt;
error=error with none value .
error1=error1 with one value is {0} .
error2=error2 with two values are {0} , {1} .
error3=error3 with three values are {0} , {1} , {2} .
error4=error4 with four values are {0} , {1} , {2} ,{3} .
</pre>
<p>下面的代码示例了actionErrors的构造：</p>
<pre>public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors actionErrors = new ActionErrors();
actionErrors.add("property1",
new ActionMessage("error"));
actionErrors.add("property2",
new ActionMessage("error1","value0"));
actionErrors.add("property2",
new ActionMessage("error2","value0","value1"));
actionErrors.add("property3",
new ActionMessage("error3","value0","value1","value2"));
actionErrors.add("property3",
new ActionMessage("error4","value0","value1","value2","value3"));
actionErrors.add("property4",
new ActionMessage("error1",new Object[]{"value0"}));
actionErrors.add("property4",
new ActionMessage("error2",new Object[]{"value0","value1"}));
actionErrors.add("property4",
new ActionMessage("error3",new Object[]{"value0","value1",
"value2"}));
actionErrors.add("property5",
new ActionMessage("error4",new Object[]{"value0","value1",
"value2","value3"}));
actionErrors.add("notBundle",
new ActionMessage("not a bundle key",false));
return actionErrors;
}
</pre>
<p>errors标签代码示例：</p>
<pre>&lt;html:errors/&gt;
&lt;br/&gt;
&lt;html:errors property="property4"/&gt;
</pre>
<p>messages标签代码示例：</p>
<pre>&lt;logic:messagesPresent&gt;
&lt;ul&gt;
&lt;html:messages id="message"&gt;
&lt;li&gt;&lt;bean:write name="message"/&gt;&lt;/li&gt;
&lt;/html:messages&gt;
&lt;/ul&gt;
&lt;/logic:messagesPresent&gt;
&lt;br/&gt;
&lt;logic:messagesPresent&gt;
&lt;ul&gt;
&lt;html:messages id="message" property="property4"&gt;
&lt;li&gt;&lt;bean:write name="message"/&gt;&lt;/li&gt;
&lt;/html:messages&gt;
&lt;/ul&gt;
&lt;/logic:messagesPresent&gt;
</pre>
<p>&nbsp;</p>
<div>图示 2. 上面的两段代码示例运行结果相同，如下所示：</div>
<img height=368 alt=运行结果 src="http://www.360doc.com/DownloadImg/13047/360318_2.gif" width=553>
<p>&nbsp;</p>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e697>html:javascript</a> </h2>
<p>html:javascript标签生成用于校验的javascript脚本代码。</p>
<p>下面的代码片段示例了html:javascript标签的基本用法，其中formName属性的值是在validation.xml文件的&lt;formset&gt;中定义的form的名称。有一点值得注意的是在确定&lt;formset&gt;时要使用合适的language属性值。</p>
<pre>&lt;html:javascript formName="dataForm"/&gt;
</pre>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e713>html:xhtml</a> </h2>
<p>html:xhtml标签在页面中一出现就是告诉该页的所有其它的Struts html标签以XHTML1.0兼容的形式输出。这和将html:html标签的xhtml属性值指定为true有些类似。如果上述情况都没有出现，Struts html标签将以html4.01兼容的形式输出。</p>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e722>logic:iterate</a> </h2>
<p>logic:iterate标签用来迭代集合，您可以使用如下方式来为这个标签指定其要叠代的集合：</p>
<ul>
    <li>使用一个运行时表达式，这个表达式的值是一个集合。
    <li>用name属性引用一个JSP Bean，这个JSP Bean本身就是一个集合。
    <li>用name属性引用一个JSP Bean，这个JSP Bean的一个属性是一个集合，这时可以联合使用property来指定这个集合。 </li>
</ul>
<p>上面所提到的集合可以是：</p>
<ul>
    <li>对象类型或原子类型的数组(Array)。
    <li>java.util.Collection的实现，包括ArrayList，Vector。
    <li>java.util.Enumeration的实现。
    <li>java.util.Iterator的实现。
    <li>java.util.Map的实现，包括HashMap，Hashtable和TreeMap。 </li>
</ul>
<p>如果您叠代的集合中含有null的值，这时需要采取一定的措施，因为这时logic:iterate不会在page作用域中创建对象。一般是使用&lt;logic:present&gt;标签或&lt;logic:notPresent&gt;标签来判断一下。</p>
<p>下面是logic:iterate叠代ArrayList的示例的对象引用关系和部分代码：</p>
<p>&nbsp;</p>
<div>图示 3. logic:iterate中对象的引用关系</div>
<img height=258 alt=logic:iterate中对象的引用关系 src="http://www.360doc.com/DownloadImg/13047/360318_3.gif" width=614>
<p>&nbsp;</p>
<p>图中的persons列表是在ListAction中填充的，在这里只是简单的加入了三个Person对象，在实际的应用中这些数据应该取自数据库。具体的代码如下：</p>
<pre>public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,	HttpServletResponse response) {
ListForm listForm = (ListForm) form;
List&lt;Person&gt; persons = new ArrayList&lt;Person&gt;();
Person person1 = new Person();
person1.setId("00001");
person1.setName("赵辰");
Person person2 = new Person();
person2.setId("00002");
person2.setName("李为芳");
Person person3 = new Person();
person3.setId("00003");
person3.setName("王微");
persons.add(person1);
persons.add(person2);
persons.add(person3);
listForm.setPersons(persons);
return mapping.findForward("success");
}
</pre>
<p>标签输出的结果为：</p>
<pre>00001--&gt;赵辰
00002--&gt;李为芳
00003--&gt;王微
</pre>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e791>logic:present</a> </h2>
<p>如果指定的值出现该标签就会创建其标签体内的内容。该标签用于以下情况：</p>
<ul>
    <li>检查具有指定名称的cookie是否出现。
    <li>检查具有指定名称的header是否出现。
    <li>检查具有指定名称的JSP Bean是否出现 或 检查具有指定名称的JSP Bean中的property属性是否出现。
    <li>检查request中指定名称的参数是否出现。
    <li>检查当前的认证用户是否与指定的安全角色相关联。
    <li>检查当前认证的主体是否具有指定的名字。 </li>
</ul>
<p>下面的代码示例了logic:present标签检查具有指定名称User-Agent的header是否出现：</p>
<pre>&lt;logic:present header="User-Agent"&gt;
您的浏览器是&lt;bean:header id="userAgent" name="User-Agent"/&gt;
&lt;bean:write name="userAgent"/&gt;。&lt;br/&gt;
&lt;/logic:present&gt;
</pre>
<p>logic:notPresent标签的应用正好和logic:present标签相反。</p>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e832>logic:messagesPresent</a> </h2>
<p>logic:messagesPresent标签用于以下情况：</p>
<ul>
    <li>在request作用域中存在一个ActionMessages对象，标签的property属性和ActionMessages中的property对应。
    <li>在request作用域中存在一个ActionErrors对象，标签的property属性和ActionErrors中的property对应。
    <li>存在一个String对象，将其转换(构造)成ActionMessage然后在添加到ActionMessages中。
    <li>存在一个String Array对象，将数组中的每一个String转换成一个ActionMessage，在将其添加到ActionMessages中。 </li>
</ul>
<p>标签的message属性值为true时将以Globals.MESSAGE_KEY为key在request作用域中查找Message，其它情况下，将name的值作为key查找，如果name 没有出现，默认值为Globals.ERROR_KEY。 </p>
<p>下面的代码示例了logic:messagesPresent标签的典型用法：</p>
<pre>&lt;logic:messagesPresent&gt;
&lt;ul&gt;
&lt;html:messages id="message"&gt;
&lt;li&gt;&lt;bean:write name="message"/&gt;&lt;/li&gt;
&lt;/html:messages&gt;
&lt;/ul&gt;
&lt;/logic:messagesPresent&gt;
</pre>
<p>标签logic:messagesNotPresent的应用正好和logic:messagesPresent的应用相反。</p>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e869>logic:empty</a> </h2>
<p>logic:empty标签是用来判断是否为空的。如果为空，该标签体中嵌入的内容就会被处理。该标签用于以下情况：</p>
<ul>
    <li>当Java对象为null时
    <li>当String对象为""时
    <li>当java.util.Collection对象中的isEmpty()返回true时
    <li>当java.util.Map对象中的isEmpty()返回true时 </li>
</ul>
<p>下面的代码示例了logic:empty标签判断集合persons是否为空：</p>
<pre>&lt;logic:empty name="listForm" property = "persons"&gt;
&lt;div&gt;集合persons为空!&lt;/div&gt;
&lt;/logic:empty&gt;
</pre>
<p>logic:notEmpty标签的应用正好和logic:empty标签相反。</p>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e902>logic:match</a> </h2>
<p>logic:match标签用来处理子串匹配问题。</p>
<p>如果指定的值匹配该标签就会创建其标签体内的内容。该标签用于以下情况： </p>
<ul>
    <li>检查具有指定名称的cookie是否与该标签的value匹配。
    <li>检查具有指定名称的header是否与该标签的value匹配。
    <li>检查具有指定名称的JSP Bean是否与该标签的value匹配 或 检查具有指定名称的JSP Bean中的property属性值是否与该标签的value匹配。
    <li>检查request中指定名称的参数值是否与该标签的value匹配。 </li>
</ul>
<p>&nbsp;</p>
<p>下面的代码示例了logic:match标签的典型用法：</p>
<pre>&lt;logic:present header="User-Agent"&gt;
&lt;logic:match header="User-Agent" value="MSIE 6.0"&gt;
MS IE 6.0
&lt;/logic:match&gt;
&lt;/logic:present&gt;
</pre>
<p>logic:notMatch标签的应用正好和logic:match标签相反。</p>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e939>logic:equal</a> </h2>
<p>这里要介绍的不只是logic:equal(=)标签，而是要介绍一类标签，这类标签完成比较运算，包括：</p>
<ul>
    <li>logic:equal(=)
    <li>logic:notEqual(!=)
    <li>logic:greaterEqual(&gt;=)
    <li>logic:lessEqual(&lt;=)
    <li>logic:graterThan(&gt;)
    <li>logic:lessThan(&lt;) </li>
</ul>
<p>该类标签的用法类似，我们只介绍logic:equal标签，其它的留给您自己去完成。</p>
<p>logic:equal是用来判断是否相等的。如果相等，该标签体中嵌入的内容就会被处理。该标签用于以下情况：</p>
<ul>
    <li>比较由该标签的cookie属性指定的cookie的值是否与该标签的value属性值相等。
    <li>比较由该标签的header属性指定的header的值是否与该标签的value属性值相等。
    <li>比较由该标签的name属性指定的JSP Bean是否与该标签的value属性值相等(property属性不出现)或比较由该标签的name属性指定的JSP Bean中的property属性值是否与该标签的value属性值相等。
    <li>比较由该标签的parameter属性指定的参数值(request中)是否与该标签的value属性值相等。 </li>
</ul>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e991>logic:forward</a> </h2>
<p>我觉得将forward和redirect这两个动作放到一起对比着介绍更加有利于理解，基于此原因也就将logic:forward和logic:redirect这两个标签也拿到这里一起介绍了。</p>
<p>让我们看看这两个动作的区别： </p>
<ul>
    <li>forward是在servlet内部执行，浏览器完全不会感知到这个动作，原始的url也不会改变，浏览器重新装载的话也只是对原始的请求进行简单的重复。
    <li>redirect则分成两个步骤：第一步是web应用程序告诉浏览器第二个url，然后浏览器向第二个url发送请求。 </li>
</ul>
<p>&nbsp;</p>
<p>redirect比forward慢，因为浏览器要做二次请求。还有就是要注意，在第一次的请求作用域(request作用域)内的bean对于第二次请求是不可见的。</p>
<p>理解了上面描述的区别也就知道了什么时候该选用logic:forward标签什么时候该选用logic:redirect标签了。logic:forward标签完成PageContext.forward()或HttpServletResponse.sendRedirect()，如何选择由控制器决定。logic:redirect标签完成HttpServletResponse.sendRedirect()。</p>
<p>在使用logic:redirect标签时我们可以向使用html:link一样构造baseurl和query参数。如果您感兴趣可以参考html:link标签。</p>
<div class=go-top><a title=回页首 href="http://www.solol.org/technologic/java/j-struts/#top"><u><font color=#0000ff>回页首</font></u></a> </div>
<h2><a name=d3e1021>总结</a> </h2>
<p>这篇指南的背景是Struts-1.2.9，其中的所有的代码示例也都是在这个版本下调试通过的。目前Struts仍然在快速的发展中，但是从开发者应用的角度来讲还是比较稳定的。因此我有理由相信其中的代码示例也可以很好的运行在其它的版本之上。最后希望这篇指南能够让您心情愉快！</p>
<img src ="http://www.blogjava.net/yesjoy/aggbug/110694.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yesjoy/" target="_blank">★yesjoy★</a> 2007-04-14 21:03 <a href="http://www.blogjava.net/yesjoy/articles/110694.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Struts标签-Logic(转贴) </title><link>http://www.blogjava.net/yesjoy/articles/110692.html</link><dc:creator>★yesjoy★</dc:creator><author>★yesjoy★</author><pubDate>Sat, 14 Apr 2007 12:56:00 GMT</pubDate><guid>http://www.blogjava.net/yesjoy/articles/110692.html</guid><wfw:comment>http://www.blogjava.net/yesjoy/comments/110692.html</wfw:comment><comments>http://www.blogjava.net/yesjoy/articles/110692.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yesjoy/comments/commentRss/110692.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yesjoy/services/trackbacks/110692.html</trackback:ping><description><![CDATA[<p><span>Struts的Logic标签可以根据特定的逻辑条件来判断网页的内容,或者循环遍历集合元素,它和HTML,Bean标签是Struts应用种最常用的三个标签.它的功能主要是比较运算,进行字符串的匹配,判断指定的内容是否存在,循环遍历集合,进行请求转发和重定向,下面具体的说明标签的用途:</span></p>
<p><span>&lt;logic:equal&gt;变量等于指定的常量</span></p>
<p><span>&lt;logic:notEqual&gt;变量不等于指定的常量</span></p>
<p><span>&lt;logic:lessThan&gt;变量小于指定的常量</span></p>
<p><span>&lt;logic:lessEqual&gt;变量小于或者等于指定的常量</span></p>
<p><span>&lt;logic:geraterThan&gt;变量大于指定的常量</span></p>
<p><span>&lt;logic:geraterEqual&gt;变量大于或等于指定的常量</span></p>
<p><span>以上这些标签都很类似<span>,有共同的属性,cookie属性指定cookie属性的值,然后用value设置的常量进行比较.header属性设置header请求头的值,也是通过value属性设置的值进行比较.parameter属性设置一个请求参数,然后也是通过value属性设置的值进行比较.name属性设置一个变量,然后用value比较.如果同时设置了name和property属性,此时name属性指定已经存在的JavaBean,property属性指定Bean的属性.这个标签感觉十分简单,用法也十分单一,下面研究一下进行字符串匹配的标签和判断特定内容的标签.</span></span></p>
<p><span>&lt;logic:match&gt;标签是判断变量种是否包含常量字符串的,&lt;logic:netMatch&gt;也判断是否不包含字符串的,用name属性定义一个字符串变量,然后用value属性的值去判断变量是否包含这个字符串或者是不包含这个字符串,判断成功返回true.</span></p>
<p><span>&lt;logic:empty&gt;和&lt;logic:netEmpty&gt;标签可以判断指定的变量是否为空的字符串,可以通过name属性来判断一个字符串是否为null.例如是请求参数的字符串.</span></p>
<p><span>&lt;logic:present&gt;和&lt;logic:notPresent&gt;标签可以判断指定的对象是否为空,这个标签的属性很多.cookie属性判断Cookie是否存在.Header属性判断HTPP请求头是否存在.role属性是判断当前的权限的用户是否是指定的安全角色.user属性是判断当前通过权限验证的用户是否拥有指定的用户名.parameter属性是判断请求的参数是否存在.name属性是用来判断指定的Bean是否存在.同时设置name和property属性就是判断Bean种的具体属性是否存在了.</span></p>
<p><span>&lt;logic:messagesPresent&gt;和&lt;logic:messagesNotPresent&gt;标签是用来判断是否在request范围内的特定的ActionMessages或者是子类ActionErrors对象.name属性是用来检索ActionMessages对象的key,property指定从ActionMessages集合对象中检索某条消息key也就是具体的ActionMessage对象.</span></p>
<p><span>进行循环遍历<span>Logic标签是Logic标签库中最复杂的标签,也是用途最广泛的标签,它能够在一个循环中遍历数组,Collection,Enumeration,Irerator或者Map中的所有元素</span></span></p>
<p><span>1)<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span>遍历集合的标签<span>&lt;logic:iterate&gt;的name属性指定需要进行遍历的集合对象,它每次从集合中检索出一个元素,然后存放在page范围内,并以id属性指定这个字符串来命名这个元素,最好是在里面嵌套一个&lt;bean:write&gt;标签,把刚刚遍历的第一个id指定的字符串输出,然后在循环在输出.length属性需要遍历的元素的数目,如果没有设置length属性,就遍历集合中的所有元素.offset属性指定开始遍历的其实位置,默认值是0.indexId属性定义一个代表当前被遍历元素的系列号,这个变量存放在page范围内,可以被&lt;bean:write&gt;标签访问输出输出的是int的数字.例如1.2.3.4等.可以用户输出输出的元素的系列号.</span></span></p>
<p><span>2)<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span>遍历<span>Map是通过&lt;logic:iterate&gt;标签,name属性指定一个HashMap,存放在request范围,然后赋给id指定的变量,indexId可以指定索引编号,然后通过&lt;bean:write&gt;标签输出出来.在HashMap的每一个元素都是一个集合对象,所以可以嵌套使用.就是说&lt;logic:inerate&gt;这个标签既可以把Collection的元素弄出来负给一个变量也可以弄Map的.所以说它的功能强大.还有一个collection属性可以设置一个表达式,这个表达式返回的结果可以作为,&lt;logic:inerate&gt;标签输出的集合或者Map.这个属性类似name属性.</span></span></p>
<p><span>最后研究一下进行请求转发和重定向的<span>Logic标签,&lt;logic:forward&gt;标签用于请求转发,它的name属性指定转发的目标,与Struts配置文件中的&lt;global-forwards&gt;元素和的子元素&lt;forward&gt;元素匹配.简单的说就是&lt;logic:forward&gt;标签的name属性定义的值,要去找到&lt;golbal-forwards&gt;子元素&lt;forward&gt;元素的匹配的name属性,然后通过path指定的路径进行转发.重定向用&lt;logic:redierct&gt;标签它的forward,href和page属性指定重定向的目标,这几个属性和&lt;html:link&gt;标签的属性用法十分相似.</span></span></p>
<p><span>关于标签的部分我就说到这里<span>,因为我个人觉得在Struts中最常用的无非也就是这三个标签库了.我以前还写过一个Struts的分页应用,过些天继续发布到我的Blog上. (网友们的支持,是我继续写技术文章的动力!)</span></span></p>
<img src ="http://www.blogjava.net/yesjoy/aggbug/110692.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yesjoy/" target="_blank">★yesjoy★</a> 2007-04-14 20:56 <a href="http://www.blogjava.net/yesjoy/articles/110692.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于struts-config.xml中“plug-in”元素的问题</title><link>http://www.blogjava.net/yesjoy/articles/106419.html</link><dc:creator>★yesjoy★</dc:creator><author>★yesjoy★</author><pubDate>Mon, 26 Mar 2007 07:10:00 GMT</pubDate><guid>http://www.blogjava.net/yesjoy/articles/106419.html</guid><wfw:comment>http://www.blogjava.net/yesjoy/comments/106419.html</wfw:comment><comments>http://www.blogjava.net/yesjoy/articles/106419.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yesjoy/comments/commentRss/106419.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yesjoy/services/trackbacks/106419.html</trackback:ping><description><![CDATA[
		<p>问题描述：</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in className</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">org.apache.struts.validator.ValidatorPlugIn</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">set</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">property property</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">pathnames</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> value</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">/WEB-INF/validator-rules.xml,/WEB-INF/validator/validation.xml</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">/&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">set</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">property property</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">stopOnFirstError</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> value</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">true</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">/&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
				<span style="COLOR: #000000">&lt;/</span>
				<span style="COLOR: #000000">plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />其中</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">set</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">property property</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">stopOnFirstError</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> value</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">true</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">/&gt;</span>
				<span style="COLOR: #000000">是什么意思？？？</span>
		</div>
		<p>再比如：</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">    </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in className</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">org.apache.struts.validator.ValidatorPlugIn</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">set</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">property property</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">pathnames</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />            value</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> /WEB-INF/validator-rules.xml,/WEB-INF/validation.xml</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">/&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #000000">&lt;/</span>
				<span style="COLOR: #000000">plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        className</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">org.springframework.web.struts.ContextLoaderPlugIn</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">set</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">property property</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">contextConfigLocation</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />            value</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">/WEB-INF/classes/applicationContext.xml</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">/&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #000000">&lt;/</span>
				<span style="COLOR: #000000">plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in</span>
				<span style="COLOR: #000000">&gt;</span>
		</div>
		<p>转贴来自：<a href="http://www.xdfbc.net/program/2007/3/22/5411908.htm">http://www.xdfbc.net/program/2007/3/22/5411908.htm</a></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">创建一个实现了org.apache.struts.action.PlugIn接口的类文件并在struts</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">config.xml中设置plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in元素。以下代码片段显示了一个plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in生命声明和一个自定义的set</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">property子元素：<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in className</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">com.oreilly.strutsckbk.CustomPlugin</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">set</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">property property</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">customData</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />                   value</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">Hello from the plugin</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">/&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">&lt;/</span>
				<span style="COLOR: #000000">plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in</span>
				<span style="COLOR: #000000">&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" />n   细节讨论：<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" />Struts提供一个 PlugIn接口能使你在启动应用程序时为你提供自定义的操作。其源代码如下：<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">package</span>
				<span style="COLOR: #000000"> org.apache.struts.action;<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" /> <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">import</span>
				<span style="COLOR: #000000"> javax.servlet.ServletException;<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">import</span>
				<span style="COLOR: #000000"> org.apache.struts.config.ModuleConfig;<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" /> <br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_499_616_Open_Image" onclick="this.style.display='none'; Codehighlighter1_499_616_Open_Text.style.display='none'; Codehighlighter1_499_616_Closed_Image.style.display='inline'; Codehighlighter1_499_616_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_499_616_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_499_616_Closed_Text.style.display='none'; Codehighlighter1_499_616_Open_Image.style.display='inline'; Codehighlighter1_499_616_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">interface</span>
				<span style="COLOR: #000000"> PlugIn </span>
				<span id="Codehighlighter1_499_616_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_499_616_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" />    </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> destroy();<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" />    </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> init(ActionServlet servlet, ModuleConfig config)<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" />        </span>
						<span style="COLOR: #0000ff">throws</span>
						<span style="COLOR: #000000"> ServletException;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />要实现一个plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in，你只需要实现这个接口并在struts</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">config.xml文件的中声明plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in元素。子类必须实现方法destroy()和init()。init()在ActionServlet启动时实例化plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in过程中执行，当ActionServlet结束时执行destroy(),一般情况下是应用程序关闭。通过在plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in元素中设置set</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">property元素，可以向PlugIn类传递参数。<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" />所有set</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">property元素都在init()方法执行之前被执行，这样就可以在init()方法中使用这些由set</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">property设置的参数了。<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" />Struts将ActionServlet的引用和ModuleConfig参数传递给init()方法。ActionServlet使的init()方法中可以将数据保存到ServletContext中。ActionServlet还可以使你能够访问更多的J2EE组件如java sources、message队列等。ModuleConfig可以让你访问当前的模块配置信息。<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" />n   举例说明：<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" />你需要定义一个plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in记录应用程序何时运行的及运行了多久。<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" />TimeTracker.java:<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">package</span>
				<span style="COLOR: #000000"> com.yourcompany.struts.plugin;<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" /> <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">import</span>
				<span style="COLOR: #000000"> java.util.Date;<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" /> <br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_1248_1601_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1248_1601_Open_Text.style.display='none'; Codehighlighter1_1248_1601_Closed_Image.style.display='inline'; Codehighlighter1_1248_1601_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1248_1601_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1248_1601_Closed_Text.style.display='none'; Codehighlighter1_1248_1601_Open_Image.style.display='inline'; Codehighlighter1_1248_1601_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> TimeTracker </span>
				<span id="Codehighlighter1_1248_1601_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_1248_1601_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" /> <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" />  </span>
						<span style="COLOR: #0000ff">private</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">long</span>
						<span style="COLOR: #000000"> startUpTimeMillis;<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" />  </span>
						<span style="COLOR: #0000ff">private</span>
						<span style="COLOR: #000000"> Date startedOn;<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" /> <br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_1343_1435_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1343_1435_Open_Text.style.display='none'; Codehighlighter1_1343_1435_Closed_Image.style.display='inline'; Codehighlighter1_1343_1435_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1343_1435_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1343_1435_Closed_Text.style.display='none'; Codehighlighter1_1343_1435_Open_Image.style.display='inline'; Codehighlighter1_1343_1435_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000"> TimeTracker( ) </span>
						<span id="Codehighlighter1_1343_1435_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_1343_1435_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" />     startUpTimeMillis </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> System.currentTimeMillis( );<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" />     startedOn </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">new</span>
								<span style="COLOR: #000000"> Date( );<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />   }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> <br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_1468_1534_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1468_1534_Open_Text.style.display='none'; Codehighlighter1_1468_1534_Closed_Image.style.display='inline'; Codehighlighter1_1468_1534_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1468_1534_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1468_1534_Closed_Text.style.display='none'; Codehighlighter1_1468_1534_Open_Image.style.display='inline'; Codehighlighter1_1468_1534_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">long</span>
						<span style="COLOR: #000000"> getUptime( ) </span>
						<span id="Codehighlighter1_1468_1534_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_1468_1534_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" />    </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> System.currentTimeMillis( ) </span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000"> startUpTimeMillis;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />  }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> <br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_1570_1598_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1570_1598_Open_Text.style.display='none'; Codehighlighter1_1570_1598_Closed_Image.style.display='inline'; Codehighlighter1_1570_1598_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1570_1598_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1570_1598_Closed_Text.style.display='none'; Codehighlighter1_1570_1598_Open_Image.style.display='inline'; Codehighlighter1_1570_1598_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000"> Date getStartedOn( ) </span>
						<span id="Codehighlighter1_1570_1598_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_1570_1598_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" />    </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> startedOn;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />  }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />创建一个PlugIn子类TimeTrackerPlugin。TimeTrackerPlugi将TimeTracker保存在ServletContext中，键名由由plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in元素的set</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">propery子元素指定：<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" />TimeTrackerPlugin.java:<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">package</span>
				<span style="COLOR: #000000"> com.yourcompany.struts.plugin;<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" /> <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">import</span>
				<span style="COLOR: #000000"> javax.servlet.ServletException;<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">import</span>
				<span style="COLOR: #000000"> org.apache.struts.action.ActionServlet;<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">import</span>
				<span style="COLOR: #000000"> org.apache.struts.action.PlugIn;<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">import</span>
				<span style="COLOR: #000000"> org.apache.struts.config.ModuleConfig;<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" /> <br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_2010_2365_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2010_2365_Open_Text.style.display='none'; Codehighlighter1_2010_2365_Closed_Image.style.display='inline'; Codehighlighter1_2010_2365_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_2010_2365_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_2010_2365_Closed_Text.style.display='none'; Codehighlighter1_2010_2365_Open_Image.style.display='inline'; Codehighlighter1_2010_2365_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> TimeTrackerPlugin </span>
				<span style="COLOR: #0000ff">implements</span>
				<span style="COLOR: #000000"> PlugIn </span>
				<span id="Codehighlighter1_2010_2365_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_2010_2365_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" /> <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" />    </span>
						<span style="COLOR: #0000ff">private</span>
						<span style="COLOR: #000000"> String contextKey;<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" />   <br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_2094_2131_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2094_2131_Open_Text.style.display='none'; Codehighlighter1_2094_2131_Closed_Image.style.display='inline'; Codehighlighter1_2094_2131_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_2094_2131_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_2094_2131_Closed_Text.style.display='none'; Codehighlighter1_2094_2131_Open_Image.style.display='inline'; Codehighlighter1_2094_2131_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />   </span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> setContextKey(String key) </span>
						<span id="Codehighlighter1_2094_2131_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_2094_2131_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" />       </span>
								<span style="COLOR: #0000ff">this</span>
								<span style="COLOR: #000000">.contextKey </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> key;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />   }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />   <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" />   </span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> init(ActionServlet servlet, ModuleConfig conf)<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_2235_2323_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2235_2323_Open_Text.style.display='none'; Codehighlighter1_2235_2323_Closed_Image.style.display='inline'; Codehighlighter1_2235_2323_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_2235_2323_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_2235_2323_Closed_Text.style.display='none'; Codehighlighter1_2235_2323_Open_Image.style.display='inline'; Codehighlighter1_2235_2323_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />         </span>
						<span style="COLOR: #0000ff">throws</span>
						<span style="COLOR: #000000"> ServletException </span>
						<span id="Codehighlighter1_2235_2323_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_2235_2323_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" />      servlet.getServletContext( ).setAttribute(contextKey, </span>
								<span style="COLOR: #0000ff">new</span>
								<span style="COLOR: #000000"> TimeTracker( ));<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />   }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> <br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_2355_2362_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2355_2362_Open_Text.style.display='none'; Codehighlighter1_2355_2362_Closed_Image.style.display='inline'; Codehighlighter1_2355_2362_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_2355_2362_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_2355_2362_Closed_Text.style.display='none'; Codehighlighter1_2355_2362_Open_Image.style.display='inline'; Codehighlighter1_2355_2362_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />   </span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> destroy( ) </span>
						<span id="Codehighlighter1_2355_2362_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_2355_2362_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/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />struts</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">config.xml:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in className</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">com.yourcompany.struts.plugin.TimeTrackerPlugin</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">set</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">property property</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">contextKey</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> value</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">timeTracker</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">/&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
				<span style="COLOR: #000000">&lt;/</span>
				<span style="COLOR: #000000">plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in</span>
				<span style="COLOR: #000000">&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" /> <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" />你可以使用如下的JSP片段访问TimTracker，并显示关于应用程序运行时间的信息。<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" /> <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" />n   你也可以在web.xml中配置一个Servlet实现plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in的功能将load</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">on</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">startup值设置为一个较低的值如1。他将在应用程序启动是自动加载并执行。容器在实例化Servlet后将调用此Servlet的init()方法。比较而言，使用plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in有更多的优势：<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">.  一般情况下Struts应用程序设置好web.xml后，在开发过程中不许要改动他的内容。在web.xml中增加servlet意味着增加了一个维护对象。<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #000000">2</span>
				<span style="COLOR: #000000">.  plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in接口提供了访问struts应用程序特有的信息的能力。<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" />plug</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">in的声明周期跟ActionSerlvet的生命周期一致。他可以保证你的struts应用程序需要的信息可用。</span>
		</div>
		<p>
				<br /> </p>
<img src ="http://www.blogjava.net/yesjoy/aggbug/106419.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yesjoy/" target="_blank">★yesjoy★</a> 2007-03-26 15:10 <a href="http://www.blogjava.net/yesjoy/articles/106419.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Struts提供的强大的HTML标签库总结</title><link>http://www.blogjava.net/yesjoy/articles/41953.html</link><dc:creator>★yesjoy★</dc:creator><author>★yesjoy★</author><pubDate>Wed, 19 Apr 2006 08:52:00 GMT</pubDate><guid>http://www.blogjava.net/yesjoy/articles/41953.html</guid><wfw:comment>http://www.blogjava.net/yesjoy/comments/41953.html</wfw:comment><comments>http://www.blogjava.net/yesjoy/articles/41953.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yesjoy/comments/commentRss/41953.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yesjoy/services/trackbacks/41953.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Struts														提供了一个强大的														HTML														标签库来帮助你构建														Web														应用程序。																																														...&nbsp;&nbsp;<a href='http://www.blogjava.net/yesjoy/articles/41953.html'>阅读全文</a><img src ="http://www.blogjava.net/yesjoy/aggbug/41953.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yesjoy/" target="_blank">★yesjoy★</a> 2006-04-19 16:52 <a href="http://www.blogjava.net/yesjoy/articles/41953.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>深入Struts 1.1(增加学习笔记)</title><link>http://www.blogjava.net/yesjoy/articles/38592.html</link><dc:creator>★yesjoy★</dc:creator><author>★yesjoy★</author><pubDate>Sat, 01 Apr 2006 03:29:00 GMT</pubDate><guid>http://www.blogjava.net/yesjoy/articles/38592.html</guid><wfw:comment>http://www.blogjava.net/yesjoy/comments/38592.html</wfw:comment><comments>http://www.blogjava.net/yesjoy/articles/38592.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yesjoy/comments/commentRss/38592.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yesjoy/services/trackbacks/38592.html</trackback:ping><description><![CDATA[
		<p>级别: 初级</p>
		<p>
				<a href="http://www-128.ibm.com/developerworks/cn/java/l-struts1-1/#author">
						<font color="#996699">王和全</font>
				</a>, <br /></p>
		<p>转自：<a href="http://www-128.ibm.com/developerworks/cn/java/l-struts1-1/">http://www-128.ibm.com/developerworks/cn/java/l-struts1-1/</a></p>
		<blockquote>作为基于MVC模式的Web应用最经典框架，Struts已经正式推出了1.1版本，该版本在以往版本的基础上，提供了许多激动人心的新功能。本文就将带你走进Struts 1.1去深入地了解这些功能。</blockquote>
		<!--START RESERVED FOR FUTURE USE INCLUDE FILES-->
		<!-- include java script once we verify teams wants to use this and it will work on dbcs and cyrillic characters -->
		<!--END RESERVED FOR FUTURE USE INCLUDE FILES-->
		<p>
				<b>说明：</b>希望本文的读者能有一定的Struts使用基础。 </p>
		<p>
				<a name="1">
						<span class="atitle">
								<font face="Arial" size="4">Model 2</font>
						</span>
				</a>
		</p>
		<p>
				<font face="Arial" size="4">
				</font>
		</p>
		<p>Struts是基于Model 2之上的，而Model 2是经典的MVC（模型－视图－控制器）模型的Web应用变体，这个改变主要是由于网络应用的特性--HTTP协议的无状态性引起的。Model 2的目的和MVC一样，也是利用控制器来分离模型和视图，达到一种层间松散耦合的效果，提高系统灵活性、复用性和可维护性。在多数情况下，你可以将Model 2与MVC等同起来。</p>
		<p>下图表示一个基于Java技术的典型网络应用，从中可以看出Model 2中的各个部分是如何对应于Java中各种现有技术的。</p>
		<br />
		<img alt="" src="http://www-128.ibm.com/developerworks/cn/java/l-struts1-1/image001.gif" />
		<br />
		<p>在利用Model 2之前，我们是把所有的表示逻辑和业务逻辑都集中在一起（比如大杂烩似的JSP），有时也称这种应用模式为Model 1，Model 1的主要缺点就是紧耦合，复用性差以及维护成本高。</p>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/java/l-struts1-1/#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="2">
						<span class="atitle">
								<font face="Arial" size="4">Struts 1.1 和Model 2</font>
						</span>
				</a>
		</p>
		<p>
				<font face="Arial" size="4">
				</font>
		</p>
		<p>既然Struts 1.1是基于Model 2之上，那它的底层机制也就是MVC，下面是Struts 1.1中的MVC实现示意图：</p>
		<br />
		<img alt="" src="http://www-128.ibm.com/developerworks/cn/java/l-struts1-1/image002.jpg" />
		<br />
		<i>图解说明：其中不同颜色代表MVC的不同部分：红色（控制器）、紫色（模型）和绿色（视图） </i>
		<p>首先，控制器（ActionServlet）进行初始化工作，读取配置文件（struts-config.xml），为不同的Struts模块初始化相应的ModuleConfig对象。比如配置文件中的Action映射定义都保存在ActionConfig集合中。相应地有ControlConfig集合、FormBeanConfig集合、ForwardConfig集合和MessageResourcesConfig集合等。</p>
		<p>
				<i>
						<b>提示：</b>模块是在Struts 1.1中新提出的概念，在稍后的内容中我们将详细介绍，你现在可以简单地把模块看作是一个子系统，它们共同组成整个应用，同时又各自独立。Struts 1.1中所有的处理都是在特定模块环境中进行的。模块的提出主要是为了解决Struts 1.0中单配置文件的问题。 </i>
		</p>
		<p>控制器接收HTTP请求，并从ActionConfig中找出对应于该请求的Action子类，如果没有对应的Action，控制器直接将请求转发给JSP或者静态页面。否则控制器将请求分发至具体Action类进行处理。</p>
		<p>在控制器调用具体Action的execute方法之前，ActionForm对象将利用HTTP请求中的参数来填充自己（可选步骤，需要在配置文件中指定）。具体的ActionForm对象应该是ActionForm的子类对象，它其实就是一个JavaBean。此外，还可以在ActionForm类中调用validate方法来检查请求参数的合法性，并且可以返回一个包含所有错误信息的ActionErrors对象。如果执行成功，ActionForm自动将这些参数信息以JavaBean（一般称之为form bean）的方式保存在Servlet Context中，这样它们就可以被其它Action对象或者JSP调用。</p>
		<p>Struts将这些ActionForm的配置信息都放在FormBeanConfig集合中，通过它们Struts能够知道针对某个客户请求是否需要创建相应的ActionForm实例。</p>
		<p>Action很简单，一般只包含一个execute方法，它负责执行相应的业务逻辑，如果需要，它也进行相应的数据检查。执行完成之后，返回一个ActionForward对象，控制器通过该ActionForward对象来进行转发工作。我们主张将获取数据和执行业务逻辑的功能放到具体的JavaBean当中，而Action只负责完成与控制有关的功能。遵循该原则，所以在上图中我将Action对象归为控制器部分。</p>
		<p>
				<i>
						<b>提示：</b>其实在Struts 1.1中，ActionMapping的作用完全可以由ActionConfig来替代，只不过由于它是公共API的一部分以及兼容性的问题得以保留。ActionMapping通过继承ActionConfig来获得与其一致的功能，你可以等同地看待它们。同理，其它例如ActionForward与ForwardConfig的关系也是如此。 </i>
		</p>
		<p>下图给出了客户端从发出请求到获得响应整个过程的图解说明。</p>
		<br />
		<img alt="" src="http://www-128.ibm.com/developerworks/cn/java/l-struts1-1/image003.jpg" />
		<br />
		<p>下面我们就来详细地讨论一下其中的每个部分，在这之前，先来了解一下模块的概念。</p>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/java/l-struts1-1/#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="3">
						<span class="atitle">
								<font face="Arial" size="4">模块</font>
						</span>
				</a>
		</p>
		<p>
				<font face="Arial" size="4">
				</font>
		</p>
		<p>我们知道，在Struts 1.0中，我们只能在web.xml中为ActionServlet指定一个配置文件，这对于我们这些网上的教学例子来说当然没什么问题，但是在实际的应用开发过程中，可能会有些麻烦。因为许多开发人员都可能同时需要修改配置文件，但是配置文件只能同时被一个人修改，这样肯定会造成一定程度上的资源争夺，势必会影响开发效率和引起开发人员的抱怨。</p>
		<p>在Struts 1.1中，为了解决这个并行开发的问题，提出了两种解决方案： 
</p>
		<ol>
				<li>多个配置文件的支持 
</li>
				<li>模块的支持 </li>
		</ol>
		<p>
		</p>
		<p>支持多个配置文件，是指你能够为ActionServlet同时指定多个xml配置文件，文件之间以逗号分隔，比如Struts提供的MailReader演示例子中就采用该种方法。</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console">  &lt;!-- Action Servlet Configuration --&gt;
  &lt;servlet&gt;
	&lt;servlet-name&gt;action&lt;/servlet-name&gt;
	&lt;servlet-class&gt;org.apache.struts.action.ActionServlet&lt;/servlet-class&gt;
	&lt;init-param&gt;
		&lt;param-name&gt;config&lt;/param-name&gt;
		&lt;param-value&gt;/WEB-INF/struts-config.xml, /WEB-INF/struts-config-registration.xml&lt;/param-value&gt;
	&lt;/init-param&gt; 
	&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;

</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>这种方法可以很好地解决修改冲突的问题，不同的开发人员可以在不同的配置文件中设置自己的Action、ActionForm等等（当然不是说每个开发人员都需要自己的配置文件，可以按照系统的功能模块进行划分）。但是，这里还是存在一个潜在的问题，就是可能不同的配置文件之间会产生冲突，因为在ActionServlet初始化的时候这几个文件最终还是需要合并到一起的。比如，在struts-config.xml中配置了一个名为success的&lt;forward&gt;，而在struts-config-registration.xml中也配置了一个同样的&lt;forward&gt;，那么执行起来就会产生冲突。</p>
		<p>为了彻底解决这种冲突，Struts 1.1中引进了模块（Module）的概念。一个模块就是一个独立的子系统，你可以在其中进行任意所需的配置，同时又不必担心和其它的配置文件产生冲突。因为前面我们讲过，ActionServlet是将不同的模块信息保存在不同的ModuleConfig对象中的。要使用模块的功能，需要进行以下的准备工作：</p>
		<p>1、为每个模块准备一个配置文件</p>
		<p>2、配置web.xml文件，通知控制器</p>
		<p>决定采用多个模块以后，你需要将这些信息告诉控制器，这需要在web.xml文件进行配置。下面是一个典型的多模块配置：</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console">&lt;init-param&gt;
	&lt;param-name&gt;config&lt;/param-name&gt;
	&lt;param-value&gt;/WEB-INF/struts-config.xml&lt;/param-value&gt;
&lt;/init-param&gt;
&lt;init-param&gt;
	&lt;param-name&gt;config/customer&lt;/param-name&gt; 
	&lt;param-value&gt;/WEB-INF/struts-config-customer.xml&lt;/param-value&gt;
&lt;/init-param&gt;
&lt;init-param&gt; 
	&lt;param-name&gt;config/order&lt;/param-name&gt;
	&lt;param-value&gt;/WEB-INF/struts-config-order.xml&lt;/param-value&gt;
&lt;/init-param&gt;

</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>要配置多个模块，你需要在原有的一个&lt;init-param&gt;（在Struts 1.1中将其对应的模块称为缺省模块）的基础之上，增加模块对应的&lt;init-param&gt;。其中&lt;param-name&gt;表示为config/XXX的形式，其中XXX为对应的模块名，&lt;param-value&gt;中还是指定模块对应的配置文件。上面这个例子说明该应用有三个模块，分别是缺省模块、customer和order，它们分别对应不同的配置文件。</p>
		<p>3、准备各个模块所需的ActionForm、Action和JSP等资源</p>
		<p>但是要注意的是，模块的出现也同时带来了一个问题，即如何在不同模块间进行转发？有两种方法可以实现模块间的转发，一种就是在&lt;forward&gt;（全局或者本地）中定义，另外一种就是利用org.apache.struts.actions.SwitchAction。</p>
		<p>下面就是一个全局的例子：</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console">    ... 
    &lt;struts-config&gt;
	... 
	&lt;global-forwards&gt;
		&lt;forward name="toModuleB"
			contextRelative="true"  
			path="/moduleB/index.do" 
		redirect="true"/&gt;   
	... 
	&lt;/global-forwards&gt;  
	...   
    &lt;/struts-config&gt;
</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>可以看出，只需要在原有的path属性前加上模块名，同时将contextRelative属性置为true即可。此外，你也可以在&lt;action&gt;中定义一个类似的本地&lt;forward&gt;。</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console">  &lt;action-mappings&gt;
	&lt;!-- Action mapping for profile form --&gt;
	&lt;action path="/login" 
	type="com.ncu.test.LoginAction"  
	name="loginForm"     
	scope="request"      
	input="tile.userLogin"
	validate="true"&gt;     
	&lt;forward name="success" contextRelative="true" path="/moduleA/login.do"/&gt; 
	&lt;/action&gt; 
  &lt;/action-mappings&gt;
</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>如果你已经处在其他模块，需要转回到缺省模块，那应该类似下面这样定义，即模块名为空。</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console">&lt;forward name="success" contextRelative="true" path="/login.do"/&gt;

</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>此外，你也可以使用org.apache.struts.actions.SwitchAction，例如：</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console">    ...
    &lt;action-mappings&gt; 
	&lt;action path="/toModule" 
	type="org.apache.struts.actions.SwitchAction"/&gt;  
	...    
    &lt;/action-mappings&gt;  
    ...
</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<font face="Lucida Console">
												<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
												<br />
												<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
										</font>
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<font face="Lucida Console">
												<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
												<br />
										</font>
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<font face="Lucida Console">
																				<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																				<br />
																		</font>
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/java/l-struts1-1/#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="4">
						<span class="atitle">
								<font face="Arial" size="4">ActionServlet</font>
						</span>
				</a>
		</p>
		<p>
				<font face="Arial" size="4">
				</font>
		</p>
		<p>我们首先来了解MVC中的控制器。在Struts 1.1中缺省采用ActionServlet类来充当控制器。当然如果ActionServlet不能满足你的需求，你也可以通过继承它来实现自己的类。这可以在/WEB-INF/web.xml中来具体指定。</p>
		<p>要掌握ActionServlet，就必须了解它所扮演的角色。首先，ActionServlet表示MVC结构中的控制器部分，它需要完成控制器所需的前端控制及转发请求等职责。其次，ActionServlet被实现为一个专门处理HTTP请求的Servlet，它同时具有servlet的特点。在Struts 1.1中它主要完成以下功能： 
</p>
		<ul>
				<li>接收客户端请求 
</li>
				<li>根据客户端的URI将请求映射到一个相应的Action类 
</li>
				<li>从请求中获取数据填充Form Bean（如果需要） 
</li>
				<li>调用Action类的execute()方法获取数据或者执行业务逻辑 
</li>
				<li>选择正确的视图响应客户 </li>
		</ul>
		<p>
		</p>
		<p>此外，ActionServlet还负责初始化和清除应用配置信息的任务。ActionServlet的初始化工作在init方法中完成，它可以分为两个部分：初始化ActionServlet自身的一些信息以及每个模块的配置信息。前者主要通过initInternal、initOther和initServlet三个方法来完成。</p>
		<p>我们可以在/WEB-INF/web.xml中指定具体的控制器以及初始参数，由于版本的变化以及Struts 1.1中模块概念的引进，一些初始参数被废弃或者移入到/WEB-INF/struts-config.xml中定义。下面列出所有被废弃的参数，相应地在web.xml文件中也不鼓励再使用。</p>
		<ul>
				<li>application 
</li>
				<li>bufferSize 
</li>
				<li>content 
</li>
				<li>debug 
</li>
				<li>factory 
</li>
				<li>formBean 
</li>
				<li>forward 
</li>
				<li>locale 
</li>
				<li>mapping 
</li>
				<li>maxFileSize 
</li>
				<li>multipartClass 
</li>
				<li>nocache 
</li>
				<li>null 
</li>
				<li>tempDir </li>
		</ul>
		<p>ActionServlet根据不同的模块来初始化ModuleConfig类，并在其中以XXXconfig集合的方式保存该模块的各种配置信息，比如ActionConfig，FormBeanConfig等。</p>
		<p>初始化工作完成之后，ActionServlet准备接收客户请求。针对每个请求，方法process(HttpServletRequest request, HttpServletResponse response)将被调用。该方法指定具体的模块，然后调用该模块的RequestProcessor的process方法。</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console">protected void process(HttpServletRequest request, 
		HttpServletResponse response) 
		throws IOException, ServletException {

	RequestUtils.selectModule(request, getServletContext());        
	getRequestProcessor(getModuleConfig(request)).process(request, response);
}
</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>RequestProcessor包含了Struts控制器的所有处理逻辑，它调用不同的processXXX方法来完成不同的处理。下表列出其中几个主要的方法：</p>
		<p>
		</p>
		<table border="1">
				<tbody>
						<tr>
								<td>方法</td>
								<td>功能</td>
						</tr>
						<tr>
								<td>processPath</td>
								<td>获取客户端的请求路径</td>
						</tr>
						<tr>
								<td>processMapping</td>
								<td>利用路径来获得相应的ActionMapping</td>
						</tr>
						<tr>
								<td>processActionForm</td>
								<td>初始化ActionForm（如果需要）并存入正确的scope中</td>
						</tr>
						<tr>
								<td>processActionCreate</td>
								<td>初始化Action</td>
						</tr>
						<tr>
								<td>processActionPerform</td>
								<td>调用Action的execute方法</td>
						</tr>
						<tr>
								<td>processForwardConfig</td>
								<td>处理Action返回的ActionForward</td>
						</tr>
				</tbody>
		</table>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/java/l-struts1-1/#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="5">
						<span class="atitle">
								<font face="Arial" size="4">ActionForm</font>
						</span>
				</a>
		</p>
		<p>
				<font face="Arial" size="4">
				</font>
		</p>
		<p>对于ActionForm你可以从以下几个方面来理解它： 
</p>
		<ol>
				<li>ActionForm表示HTTP窗体中的数据，可以将其看作是模型和视图的中介，它负责保存视图中的数据供模型或者视图使用。Struts 1.1文档中把它比作HTTP和Action之间的防火墙，这体现了ActionForm具有的过滤保护的作用，只有通过ActionForm验证的数据才能够发送到Action处理。 
</li>
				<li>ActionForm是与一个或多个ActionConfig关联的JavaBean，在相应的action的execute方法被调用之前，ActionForm会自动利用请求参数来填充自己（初始化属性）。 
</li>
				<li>ActionForm是一个抽象类，你必须通过继承来实现自己的类。 </li>
		</ol>
		<p>
		</p>
		<p>ActionForm首先利用属性的getter和setter方法来实现初始化，初始化完毕后，ActionForm的validate方法被调用，你可以在其中来检查请求参数的正确性和有效性，并且可以将错误信息以ActionErrors的形式返回到输入窗体。否则，ActionForm将被作为参数传给action的execute方法以供使用。</p>
		<p>ActionForm bean的生命周期可以设置为session（缺省）和request，当设置为session时，记得在reset方法中将所有的属性重新设置为初始值。</p>
		<p>由于ActionForm对应于HTTP窗体，所以随着页面的增多，你的ActionForm将会急速增加。而且可能同一类型页面字段将会在不同的ActionForm中出现，并且在每个ActionForm中都存在相同的验证代码。为了解决这个问题，你可以为整个应用实现一个ActionForm或者至少一个模块对应于一个ActionForm。</p>
		<p>但是，聚合的代价就是复用性很差，而且难维护。针对这个问题，在Struts 1.1中提出了DynaActionForm的概念。</p>
		<p>
				<b>DynaActionForm类</b>
		</p>
		<p>DynaActionForm的目的就是减少ActionForm的数目，利用它你不必创建一个个具体的ActionForm类，而是在配置文件中配置出所需的虚拟ActionForm。例如，在下表中通过指定&lt;form-bean&gt;的type为"org.apache.struts.action.DynaActionForm"来创建一个动态的ActionForm--loginForm。</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console">&lt;form-beans&gt;
	&lt;form-bean name="loginForm" type="org.apache.struts.action.DynaActionForm"&gt;  
		&lt;form-property name="actionClass" type="java.lang.String"/&gt;
		&lt;form-property name="username" type="java.lang.String"/&gt;
		&lt;form-property name="password" type="java.lang.String"/&gt; 
	&lt;/form-bean&gt; 
&lt;/form-beans&gt;

</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>动态的ActionForm的使用方法跟普通的ActionForm相同，但是要注意一点。普通的ActionForm对象需要为每个属性提供getter和setter方法，以上面的例子而言，我们需要提供getUsername() 和 setUsername()方法取得和设置username属性，同样地有一对方法用于取得和设置password属性和actionClass属性。</p>
		<p>如果使用DynaActionForm，它将属性保存在一个HashMap类对象中，同时提供相应的get(name) 和 set(name)方法，其中参数name是要访问的属性名。例如要访问DynaActionForm中username的值，可以采用类似的代码：</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console">String username = (String)form.get("username")；

</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>由于值存放于一个HashMap对象，所以要记得对get()方法返回的Object对象做强制性类型转换。正是由于这点区别，如果你在Action中非常频繁地使用ActionForm对象，建议还是使用普通的ActionForm对象。</p>
		<p>在Struts 1.1中，除了DynaActionForm以外，还提供了表单输入自动验证的功能，在包org.apache.struts.validator中提供了许多有用的类，其中最常见的就是DynaValidatorForm类。</p>
		<p>
				<b>DynaValidatorForm类</b>
		</p>
		<p>DynaValidatorForm是DynaActionForm的子类，它能够提供动态ActionForm和自动表单输入验证的功能。和使用DynaActionForm类似，你必须首先在配置文件中进行配置：</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console">&lt;form-beans&gt;
	&lt;form-bean name="loginForm" type="org.apache.struts.validator.DynaValidatorForm"&gt; 
		&lt;form-property name="actionClass" type="java.lang.String"/&gt;     
		&lt;form-property name="username" type="java.lang.String"/&gt; 
		&lt;form-property name="password" type="java.lang.String"/&gt;  
	&lt;/form-bean&gt;
&lt;/form-beans&gt;

</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>同时要定义验证的插件：</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console">  &lt;plug-in className="org.apache.struts.validator.ValidatorPlugIn"&gt;
	&lt;set-property property="pathnames"  
	value="/WEB-INF/validator-rules.xml,  
	/WEB-INF/validation.xml"/&gt;
  &lt;/plug-in&gt;

</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>其中的validator.xml和validator-rules.xml分别表示验证定义和验证规则的内容（可以合并在一起），比如针对上例中的DynaValidatorForm，我们有如下验证定义（validator.xml）：</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console">&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
&lt;!DOCTYPE form-validation PUBLIC  
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN"  
"http://jakarta.apache.org/commons/dtds/validator_1_0.dtd"&gt;
&lt;!--    Validation Rules    $Id: validation.xml--&gt;

&lt;form-validation&gt;  
&lt;!-- ========== Default Language Form Definitions ===================== --&gt;
&lt;formset&gt;  
	&lt;form name="loginForm"&gt;     
		&lt;field property="username" depends="required, minlength,maxlength"&gt; 
			&lt;arg0   key="prompt.username"/&gt;          
			&lt;arg1   key="${var:minlength}" name="minlength" resource="false"/&gt;       
			&lt;arg2   key="${var:maxlength}" name="maxlength" resource="false"/&gt;              
			&lt;var&gt;                
				&lt;var-name&gt;maxlength&lt;/var-name&gt;    
				&lt;var-value&gt;16&lt;/var-value&gt;         
			&lt;/var&gt;          
			&lt;var&gt;      
				&lt;var-name&gt;minlength&lt;/var-name&gt;     
				&lt;var-value&gt;3&lt;/var-value&gt;         
			&lt;/var&gt;       
		&lt;/field&gt;     
		&lt;field property="password" depends="required, minlength,maxlength" bundle="alternate"&gt;          
			&lt;arg0   key="prompt.password"/&gt;   
			&lt;arg1   key="${var:minlength}" name="minlength" resource="false"/&gt;          
			&lt;arg2   key="${var:maxlength}" name="maxlength" resource="false"/&gt;  
			&lt;var&gt;              
				&lt;var-name&gt;maxlength&lt;/var-name&gt;     
				&lt;var-value&gt;16&lt;/var-value&gt;        
			&lt;/var&gt;          
			&lt;var&gt;      
				&lt;var-name&gt;minlength&lt;/var-name&gt; 
				&lt;var-value&gt;3&lt;/var-value&gt;       
			&lt;/var&gt;        
		&lt;/field&gt;    
	&lt;/form&gt;   
&lt;/formset&gt;
&lt;/form-validation&gt;
</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>从上述定义中，我们可以看到对于字段username有三项验证：required, minlength, maxlength，意思是该字段不能为空，而且长度在3和16之间。而validator-rules.xml文件则可以采用Struts提供的缺省文件。注意在&lt;form-bean&gt;中定义的form是如何与validation.xml中的form关联起来的。最后，要启动自动验证功能，还需要将Action配置的validate属性设置为true。</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console">&lt;action path="/login"  
type="com.ncu.test.LoginAction"
name="loginForm"          
scope="request"         
input="tile.userLogin"validate="true"&gt;

</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>此时，Struts将根据xml配置文件中的定义来检验表单输入，并将不符合要求的错误信息输出到页面。但是你可能会想：这个功能虽然好，可是什么检验都跑到服务器端执行，效率方面和用户易用性方面是不是有些问题？你可能会怀念起那简单的JavaScript客户端验证。</p>
		<p>不用担心，在Struts 1.1中也支持JavaScript客户端验证。如果你选择了客户端验证，当某个表单被提交以后，Struts 1.1启动客户端验证，如果浏览器不支持JavaScript验证，则服务器端验证被启动，这种双重验证机制能够最大限度地满足各种开发者的需要。JavaScript验证代码也是在validator-rules.xml文件中定义的。要启动客户端验证，你必须在相应的JSP文件中做如下设置： 
</p>
		<ol>
				<li>为&lt;html:form&gt;增加onsubmit属性 
</li>
				<li>设置Javascript支持 </li>
		</ol>
		<p>
		</p>
		<p>下表中列出了一JSP文件的示例代码，红字部分为Javascript验证所需代码。</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console">&lt;%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %&gt;
&lt;table bgcolor="#9AFF9A" cellspacing="0" cellpadding="10" border="1" width="100%"&gt;
	&lt;tr&gt;
	&lt;td&gt; 
	&lt;table cellspacing="0" cellpadding="0" border="0" width="100%"&gt; 
	&lt;tr bgcolor="#696969"&gt; 
		&lt;td align="center"&gt;     
		&lt;font color="#FFFFFF"&gt;Panel 3: Profile&lt;/font&gt;  
		&lt;/td&gt;
		&lt;/tr&gt; 
	&lt;tr&gt;  
		&lt;td&gt;&lt;br&gt; 
		&lt;html:errors/&gt;  
		&lt;html:form action="/login.do" focus="username"  onsubmit="return validateLoginForm(this);"&gt;  
		&lt;html:hidden property="actionClass"/&gt;   
		&lt;center&gt;      
		&lt;table&gt;      
			&lt;tr&gt;        
			&lt;td&gt;UserName:&lt;/td&gt;   
			&lt;td&gt;&lt;html:text property="username" size="20"/&gt;&lt;/td&gt; 
			&lt;/tr&gt; 
			&lt;tr&gt;  
			&lt;td&gt;Password:&lt;/td&gt;   
			&lt;td&gt;&lt;html:password property="password" size="20"/&gt;&lt;/td&gt;    
			&lt;/tr&gt;  
			&lt;tr&gt;  
			&lt;td colspan=2&gt;&lt;html:submit property="submitProperty" value="Submit"/&gt;&lt;/td&gt;     
		&lt;/table&gt;   
		&lt;/center&gt;  
		&lt;/html:form&gt; 
		&lt;html:javascript formName="loginForm" dynamicJavascript="true" staticJavascript="false"/&gt;  
	
	&lt;script language="Javascript1.1" src="staticJavascript.jsp"&gt;&lt;/script&gt;  
	&lt;/td&gt; 
	&lt;/tr&gt; 
	&lt;/table&gt;
	&lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;
</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>其中onsubmit的值为"return validateLoginForm(this);"，它的语法为：</p>
		<p>return validate + struts-config.xml中定义的form-bean名称 + (this);</p>
		<p>staticJavascript.jsp的内容为：</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console">&lt;%@ page language="java" %&gt;
&lt;%-- set document type to Javascript (addresses a bug in Netscape according to a web resource --%&gt;
&lt;%@ page contentType="application/x-javascript" %&gt;
&lt;%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %&gt;
&lt;html:javascript dynamicJavascript="false" staticJavascript="true"/&gt;


</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>如果validator-rules.xml中定义的基本验证功能不能满足你的需求，你可以自己添加所需的验证类型。</p>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/java/l-struts1-1/#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="6">
						<span class="atitle">
								<font face="Arial" size="4">Action</font>
						</span>
				</a>
		</p>
		<p>
				<font face="Arial" size="4">
				</font>
		</p>
		<p>我们通过继承Action类来实现具体的执行类。具体Action类的功能一般都在execute（以前是perform方法）方法中完成，其中主要涉及到以下几个方面： 
</p>
		<ol>
				<li>辅助ActionForm进行一些表单数据的检查。 
</li>
				<li>执行必要的业务逻辑，比如存取数据库，调用实体bean等。 
</li>
				<li>更新服务器端的bean数据，后续对象中可能会用到这些数据，比如在JSP中利用bean:write来获得这些数据。 
</li>
				<li>根据处理结果决定程序的去处，并以ActionForward对象的形式返回给ActionServlet。 </li>
		</ol>
		<p>
		</p>
		<p>
				<i>
						<b>提示：</b>由于在Action和ActionForm中都可以实现验证方法，那么如何来安排它们之间的分工呢？一般来说，我们秉着MVC分离的原则，也就是视图级的验证工作放在ActionForm来完成，比如输入不能为空，email格式是否正确，利用ValidatorForm可以很轻松地完成这些工作。而与具体业务相关的验证则放入Action中，这样就可以获得最大ActionForm重用性的可能。 </i>
		</p>
		<p>前面我们提到过，我们主张将业务逻辑执行分离到单独的JavaBean中，而Action只负责错误处理和流程控制。而且考虑到重用性的原因，在执行业务逻辑的JavaBean中不要引用任何与Web应用相关的对象，比如HttpServletRequest，HttpServletResponse等对象，而应该将其转化为普通的Java对象。关于这一点，可以参考Petstore中WAF框架的实现思路。</p>
		<p>此外，你可能还注意到execute与perform的一个区别：execute方法简单地掷出Exception异常，而perform方法则掷出ServletException和IOException异常。这不是说Struts 1.1在异常处理功能方面弱化了，而是为了配合Struts 1.1中一个很好的功能--宣称式异常处理机制。</p>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/java/l-struts1-1/#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="7">
						<span class="atitle">
								<font face="Arial" size="4">宣称式异常处理</font>
						</span>
				</a>
		</p>
		<p>
				<font face="Arial" size="4">
				</font>
		</p>
		<p>和EJB中的宣称式事务处理概念类似，宣称式异常处理其实就是可配置的异常处理，你可以在配置文件中指定由谁来处理Action类中掷出的某种异常。你可以按照以下步骤来完成该功能： 
</p>
		<ol>
				<li>实现org.apache.struts.action.ExceptionHandler的子类，覆盖execute方法，在该方法中处理异常并且返回一个ActionForward对象 
</li>
				<li>在配置文件中配置异常处理对象，你可以配置一个全局的处理类或者单独为每个Action配置处理类 </li>
		</ol>
		<p>
		</p>
		<p>下表就定义了一个全局的处理类CustomizedExceptionHandler，它被用来处理所有的异常。</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console">&lt;global-exceptions&gt; 
&lt;exception 
	handler="com.yourcorp.CustomizedExceptionHandler" 
	key="global.error.message" 
	path="/error.jsp"    
	scope="request"    
	type="java.lang.Exception"/&gt;
&lt;/global-exceptions&gt;

</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>其中具体的参数含义，可以参考ExceptionHandler.java源文件。</p>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/java/l-struts1-1/#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="8">
						<span class="atitle">
								<font face="Arial" size="4">taglib</font>
						</span>
				</a>
		</p>
		<p>
				<font face="Arial" size="4">
				</font>
		</p>
		<p>讲完了模型和控制器，接下来我们要涉及的是视图。视图的角色主要是由JSP来完成，从JSP的规范中可以看出，在视图层可以"折腾"的技术不是很多，主要的就是自定义标记库的应用。Struts 1.1在原有的四个标记库的基础上新增了两个标记库--Tiles和Nested。</p>
		<p>其中Tiles除了替代Template的基本模板功能外，还增加了布局定义、虚拟页面定义和动态页面生成等功能。Tiles强大的模板功能能够使页面获得最大的重用性和灵活性，此外可以结合Tiles配置文件中的页面定义和Action的转发逻辑，即你可以将一个Action转发到一个在Tiles配置文件中定义的虚拟页面，从而减少页面的数量。比如，下表中的Action定义了一个转发路径，它的终点是tile.userMain，而后者是你在Tiles配置文件中定义的一个页面。</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console">&lt;!-- ========== Action Mapping Definitions ============================== --&gt;
&lt;action-mappings&gt;  
&lt;!-- Action mapping for profile form --&gt; 
	&lt;action path="/login"   
		type="com.ncu.test.LoginAction"      
		name="loginForm"    
		scope="request"     
		input="tile.userLogin"
		validate="true"&gt;     
		&lt;forward name="success" path="tile.userMain"/&gt;   
	&lt;/action&gt; 
&lt;/action-mappings&gt;
</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>Tiles配置文件：tiles-defs.xml</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console">&lt;!DOCTYPE tiles-definitions PUBLIC 
"-//Apache Software Foundation//DTD Tiles Configuration//EN"       "http://jakarta.apache.org/struts/dtds/tiles-config.dtd"&gt;
&lt;tiles-definitions&gt;  
&lt;!-- =======================================================  --&gt; 
&lt;!-- Master definitions                                       --&gt;
&lt;!-- =======================================================  --&gt; 
&lt;!-- Page layout used as root for all pages. --&gt; 

&lt;definition name="rootLayout" path="/tiles-layouts/rootLayout.jsp"&gt; 
	&lt;put name="titleString" value="CHANGE-ME"/&gt;   
	&lt;put name="topMenu" value="/tiles-components/topMenu.jsp"/&gt; 
	&lt;put name="leftMenu" value="/tiles-components/panel1.jsp"/&gt;  
	&lt;put name="body" value="CHANGE-ME"/&gt;   
	&lt;put name="footer" value="/tiles-components/footer.jsp"/&gt; 
&lt;/definition&gt; 

&lt;!-- =======================================================  --&gt; 
&lt;!-- Page definitions 					--&gt;  
&lt;!-- =======================================================  --&gt; 

&lt;!-- User Login page --&gt; 
&lt;definition name="tile.userLogin" extends="rootLayout"&gt; 
	&lt;put name="titleString" value="User Login"/&gt;  
	&lt;put name="body" value="/src/userLogin.jsp"/&gt; 
&lt;/definition&gt;  
&lt;!-- User Main page --&gt; 
&lt;definition name="tile.userMain" extends="rootLayout"&gt; 
	&lt;put name="titleString" value="User Main"/&gt;  
	&lt;put name="body" value="/src/userMain.jsp"/&gt; 
&lt;/definition&gt;
&lt;/tiles-definitions&gt;
</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>而Nested标记库的作用是让以上这些基本标记库能够嵌套使用，发挥更大的作用。</p>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/java/l-struts1-1/#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="9">
						<span class="atitle">
								<font face="Arial" size="4">Commons Logging 接口</font>
						</span>
				</a>
		</p>
		<p>
				<font face="Arial" size="4">
				</font>
		</p>
		<p>所谓的Commons Logging接口，是指将日志功能的使用与日志具体实现分开，通过配置文件来指定具体使用的日志实现。这样你就可以在Struts 1.1中通过统一的接口来使用日志功能，而不去管具体是利用的哪种日志实现，有点于类似JDBC的功能。Struts 1.1中支持的日志实现包括：Log4J，JDK Logging API， LogKit，NoOpLog和SimpleLog。</p>
		<p>你可以按照如下的方式来使用Commons Logging接口（可以参照Struts源文中的许多类实现）：</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console">package com.foo;
// ...
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
//...
	public class Foo {    
	// ...    
	private static Log log = LogFactory.getLog(Foo.class);
	// ...    
	public void setBar(Bar bar) {       
		if (log.isTraceEnabled()) {         
			log.trace("Setting bar to " + bar);   
		}      
	this.bar = bar;   
	}
// ...
}
</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>而开启日志功能最简单的办法就是在WEB-INF/classes目录下添加以下两个文件：</p>
		<p>commons-logging.properties文件：</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console"># Note: The Tiles framework now uses the commons-logging package to output different information or debug statements. 
Please refer to this package documentation to enable it. The simplest way to enable logging is to create two files in 
WEB-INF/classes:
# commons-logging.properties
# org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
# simplelog.properties
# # Logging detail level,
# # Must be one of ("trace", "debug", "info", "warn", "error", or "fatal").
#org.apache.commons.logging.simplelog.defaultlog=trace
org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog

</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>simplelog.properties文件：</p>
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<font face="Lucida Console"># Logging detail level,
# Must be one of ("trace", "debug", "info", "warn", "error", or "fatal").
org.apache.commons.logging.simplelog.defaultlog=fatal

</font>
												</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>这里我们采用的日志实现是SimpleLog，你可以在simplelog.properties文件指定日志明细的级别：trace，debug，info，warn，error和fatal，从trace到fatal错误级别越来越高，同时输出的日志信息也越来越少。而这些级别是和org.apache.commons.logging.log接口中的方法一一对应的。这些级别是向后包含的，也就是前面的级别包含后面级别的信息。</p>
<img src ="http://www.blogjava.net/yesjoy/aggbug/38592.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yesjoy/" target="_blank">★yesjoy★</a> 2006-04-01 11:29 <a href="http://www.blogjava.net/yesjoy/articles/38592.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>构建Spring基础代码</title><link>http://www.blogjava.net/yesjoy/articles/36094.html</link><dc:creator>★yesjoy★</dc:creator><author>★yesjoy★</author><pubDate>Sun, 19 Mar 2006 12:12:00 GMT</pubDate><guid>http://www.blogjava.net/yesjoy/articles/36094.html</guid><wfw:comment>http://www.blogjava.net/yesjoy/comments/36094.html</wfw:comment><comments>http://www.blogjava.net/yesjoy/articles/36094.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yesjoy/comments/commentRss/36094.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yesjoy/services/trackbacks/36094.html</trackback:ping><description><![CDATA[1． Action接口:<br />Action 接口定义了一个execute 方法，在我们示例中，不同的Action 实现提供了各自的<br />execute方法，以完成目标逻辑。<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: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">interface</span><span style="COLOR: #000000"> Action {<br />  </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> String execute(String str);<br />}</span></div>2． Action接口的两个实现UpperAction、LowerAction<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: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> UpperAction </span><span style="COLOR: #0000ff">implements</span><span style="COLOR: #000000"> Action {<br /> </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> String message;<br /> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> String getMessage() {<br /> </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> message;<br /> }<br /> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> setMessage(String string) {<br />  message </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> string;<br /> }<br /> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> String execute(String str) {<br />  </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> (getMessage() </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> str).toUpperCase();<br /> }<br />}</span></div>UpperAction将其message属性与输入字符串相连接，并返回其大写形式。<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: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> LowerAction </span><span style="COLOR: #0000ff">implements</span><span style="COLOR: #000000"> Action {<br /> </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> String message;<br /> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> String getMessage() {<br />  </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> message;<br /> }<br /> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> setMessage(String string) {<br />  message </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> string;<br /> }<br /> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> String execute(String str) {<br />  </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> (getMessage()</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">str).toLowerCase();<br /> }<br />}</span></div>LowerAction将其message属性与输入字符串相连接，并返回其小写形式。<br />3． Spring配置文件（bean.xml）<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: #0000ff">&lt;</span><span style="COLOR: #800000">beans</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">Spring Quick Start</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">bean </span><span style="COLOR: #ff0000">id</span><span style="COLOR: #0000ff">="TheAction"</span><span style="COLOR: #ff0000"><br />class</span><span style="COLOR: #0000ff">="net.xiaxin.spring.qs.UpperAction"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="message"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">HeLLo</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">bean</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">beans</span><span style="COLOR: #0000ff">&gt;</span></div>（请确保配置bean.xml位于工作路径之下，注意工作路径并不等同于CLASSPATH ，eclipse<br />的默认工作路径为项目根路径，也就是.project文件所在的目录，而默认输出目录/bin是项目<br />CLASSPATH的一部分，并非工作路径。）<br />4． 测试代码<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: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> testQuickStart() {<br /> ApplicationContext ctx</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"><br />FileSystemXmlApplicationContext(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">bean.xml</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /> Action action </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (Action) ctx.getBean(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">TheAction</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /> System.out.println(action.execute(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Rod Johnson</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br />}</span></div>可以看到，上面的测试代码中，我们根据"bean.xml"创建了一个ApplicationContext实<br />例，并从此实例中获取我们所需的Action实现。<br />运行测试代码，我们看到控制台输出：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">……<br />HELLO ROD JOHNSON</span></div>我们将bean.xml中的配置稍加修改：<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: #0000ff">&lt;</span><span style="COLOR: #800000">bean </span><span style="COLOR: #ff0000">id</span><span style="COLOR: #0000ff">="TheAction" </span><span style="COLOR: #ff0000">class</span><span style="COLOR: #0000ff">="net.xiaxin.spring.qs.LowerAction"</span><span style="COLOR: #0000ff">/&gt;</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">……<br />hello rod johnson</span></div>示例完成！<br />很简单的示例，的确很简单，甚至简单到了不够真实。不过，不知大家从这个最简单的例子中看出了什么？真的只是打印输出了两行不痛不痒的问候语？<br />仔细观察一下上面的代码，可以看到：<br />1． 我们的所有程序代码中（除测试代码之外），并没有出现Spring中的任何组件。<br />2． UpperAction和LowerAction的Message属性均由Spring通过读取配置文件（bean.xml）动<br />态设置。<br />3． 客户代码（这里就是我们的测试代码）仅仅面向接口编程，而无需知道实现类的具体名称。同时，<br />我们可以很简单的通过修改配置文件来切换具体的底层实现类。<br />上面所说的这些，对于我们的实际开发有何帮助？<br />Ø 首先，我们的组件并不需要实现框架指定的接口，因此可以轻松的将组件从Spring中脱离，甚至不需要任何修改（这在基于EJB框架实现的应用中是难以想象的）。<br />Ø 其次，组件间的依赖关系减少，极大改善了代码的可重用性。<br />Spring的依赖注入机制，可以在运行期为组件配置所需资源，而无需在编写组件代码时就加以指定，从而在相当程度上降低了组件之间的耦合。<br />上面的例子中，我们通过Spring，在运行期动态将字符串 “HeLLo” 注入到Action实现类的Message属性中。<br />现在假设我们回到传统的实现模式，应该如何处理？<br />一般的处理办法也就是编写一个Helper类（辅助类），完成配置文件读写功能，然后在各个Action的构造函数中，调用这个Helper类设置message属性值。此时，我们的组件就与这个Helper类库建立了依赖关系，之后我们需要在其他系统中重用这个组件的话，也必须连同这个Helper类库一并移植。实际开发中，依赖关系往往并非如此简单，组件与项目基层代码之间复杂的关联，使得组件重用性大大下降。<br />Spring通过依赖注入模式，将依赖关系从编码中脱离出来，从而大大降低了组件之间的耦合，<br />实现了组件真正意义上的即插即用。这也是Spring最具价值的特性之一。<br />Ø 面向接口编程。<br />诚然，即使没有Spring，实现面向接口的设计也不困难。Spring对于面向接口设计的意义，在于它为面向接口编程提供了一个更加自然的平台。基于Spring开发，程序员会自然而然倾向于使用接口来定义不同层次之间的关联关系，这种自发的倾向性，来自于Spring所提供的简单舒适的依赖注入实现。Spring使得接口的定义和使用不再像传统编码过程中那么繁琐（传统编码过程中，引入一个接口，往往也意味着同时要引入一个Factory类，也许还有一个额外的配置文件及其读写代码）。<br /><img src ="http://www.blogjava.net/yesjoy/aggbug/36094.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yesjoy/" target="_blank">★yesjoy★</a> 2006-03-19 20:12 <a href="http://www.blogjava.net/yesjoy/articles/36094.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Struts-config.xml配置文件讲解</title><link>http://www.blogjava.net/yesjoy/articles/36057.html</link><dc:creator>★yesjoy★</dc:creator><author>★yesjoy★</author><pubDate>Sun, 19 Mar 2006 05:56:00 GMT</pubDate><guid>http://www.blogjava.net/yesjoy/articles/36057.html</guid><wfw:comment>http://www.blogjava.net/yesjoy/comments/36057.html</wfw:comment><comments>http://www.blogjava.net/yesjoy/articles/36057.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yesjoy/comments/commentRss/36057.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yesjoy/services/trackbacks/36057.html</trackback:ping><description><![CDATA[Struts的核心是struts-config.xml配置文件，在这个文件里描述了所有的Struts组件。在这里包括配置主要的组件及次要的组件，下面是struts-config.xml包含主要元素的内容：<br /><br />一、    struts-config.xml的主要元素：<br />&lt;?xml version=”1.0” encoding=”ISO-8859-1”?&gt;<br />&lt;!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"<br />"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"&gt;<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: #0000ff">&lt;</span><span style="COLOR: #800000">struts-config</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">   <br /><br />   </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">data-sources</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />       </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">data-source</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />       </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">data-source</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />   </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">data-sources</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><br />   </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">form-beans</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />       </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">form-bean </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />   </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">form-beans</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><br />   </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">global-forwards</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />       </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">forward </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />   </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">global-forwards</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><br />   </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">action-mappings</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />       </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">action </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />   </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">action-mappings</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><br />   </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">controller </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><br />   </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">message-resources </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><br />   </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">plug-in </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">struts-config</span><span style="COLOR: #0000ff">&gt;</span></div>注意：以上各元素的顺序是非常重要的，你的struts-config.xml配置文件必须按照这个顺序进行配置，否则在你的容器启动的时候就会出错。<br /><br />二、    struts-config.xml的子元素：<br />1．&lt;icon / &gt;子元素<br />   它包含&lt;small-icon / &gt;及&lt;large-icon / &gt;，它的作用是图形化其父元素，&lt;small-icon/&gt;的内容是一个16x16的图像文件，而&lt;large-icon/&gt;的内容是一个32x32的图像文件。如下例子：<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: #0000ff">&lt;</span><span style="COLOR: #800000">icon</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />  </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">small-icon</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    /images/smalllogo.gif<br />  </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">small-icon</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />  </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">large-icon</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    /images/largelogo.gif<br />  </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">large-icon</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">icon</span><span style="COLOR: #0000ff">&gt;</span></div>2．&lt;display-name / &gt;子元素<br />   它提供对父元素的短文字（short textual）描述信息，如下：<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: #0000ff">&lt;</span><span style="COLOR: #800000">display-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />   short textual discription of its parent element<br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">display-name</span><span style="COLOR: #0000ff">&gt;</span></div><br />3．&lt;description / &gt;子元素<br />   它提供对父元素的完全（full-length textual）的描述信息，如下：<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: #0000ff">&lt;</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />   full-length textual discription of its parent element<br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">description</span><span style="COLOR: #0000ff">&gt;</span></div><br />4．&lt;set-property / &gt;子元素<br />       它用来设置它的父元素中设定的JavaBean的属性值，它一般用在指定的GenericDataSource 属性，扩展的ActionMappings以及扩展的 global forwards。如下：<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: #0000ff">&lt;</span><span style="COLOR: #800000">set-property <br />  </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">="name of bean property"</span><span style="COLOR: #ff0000">       <br />value</span><span style="COLOR: #0000ff">="value of bean property"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</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: #0000ff">&lt;</span><span style="COLOR: #800000">set-property </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">="driverClass"</span><span style="COLOR: #ff0000"> value</span><span style="COLOR: #0000ff">="org.gjt.mm.mysql.Driver"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">set-property </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">="user"</span><span style="COLOR: #ff0000"> value</span><span style="COLOR: #0000ff">="admin"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">set-property </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">="maxCount"</span><span style="COLOR: #ff0000"> value</span><span style="COLOR: #0000ff">="4"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">set-property </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">="minCount"</span><span style="COLOR: #ff0000"> value</span><span style="COLOR: #0000ff">="2"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"> <br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">set-property </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">="password"</span><span style="COLOR: #ff0000"> value</span><span style="COLOR: #0000ff">=""</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"> <br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">set-property </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">="url"</span><span style="COLOR: #ff0000"> value</span><span style="COLOR: #0000ff">="jdbc:mysql://localhost:3306/struts"</span><span style="COLOR: #0000ff">/&gt;</span></div><br />三、    配置JDBC数据源<br />其配置形式如下：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">data-sources</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">data-source</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">set-property </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">="driverClass"</span><span style="COLOR: #ff0000"> value</span><span style="COLOR: #0000ff">="fully qualified path of JDBC driver"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">set-property </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">="url"</span><span style="COLOR: #ff0000"> value</span><span style="COLOR: #0000ff">="data source URL"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">set-property </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">=”mincount” </span><span style="COLOR: #ff0000">value</span><span style="COLOR: #0000ff">="the minimum number of connections to open"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">set-property </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">="password"</span><span style="COLOR: #ff0000"> value</span><span style="COLOR: #0000ff">="the password used to create connections"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">set-property </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">="user"</span><span style="COLOR: #ff0000"> value</span><span style="COLOR: #0000ff">="the username used to create connections"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">data-source</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">data-sources</span><span style="COLOR: #0000ff">&gt;</span></div>&lt;data-source&gt;的属性及其描述信息如下：<br />属  性    描 述 信 息<br />Key    绑定在ServletContext上的DataSource实例的索引键，若不设定则缺省为Action.DATA_SOURCE_KEY，如果在应用程序中有多于一个的DataSource，则必须设置Key的值。<br />DriverClass    所用的JDBC驱动类(必须的)如：com.microsoft.jdbc.sqlserver.SQLServerDriver<br />url    所用的JDBC的URL(必须的)如：jdbc:microsoft:sqlserver://xg088:1433<br />MaxCount    同时打开的最大连结数，缺省值为2(可选的)<br />MinCount    同时打开的最小连结数，缺省值为1(可选的)<br />User    连结到数据库的用户名(必须的)<br />Password    连结到数据库的密码(必须的)<br />Description    关于DataSource的描述信息(可选的)<br />ReadOnly    如果设为true，则表示该连结是只读的，缺省为false。(可选的)<br />LoginTimeout    创建连结的最大允许时间，以秒为单位。(可选的)<br />AutoCommit    如果为true，则每次execute之后会强制回滚。缺省为true。(可选的)<br />举例说明：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">data-sources</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">data-source</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">set-property </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">=”key” </span><span style="COLOR: #ff0000">value</span><span style="COLOR: #0000ff">=” </span><span style="COLOR: #ff0000">value</span><span style="COLOR: #0000ff">="WILEY_DATA_SOURCE"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">set-property </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">="driverClass"</span><span style="COLOR: #ff0000"> value</span><span style="COLOR: #0000ff">="org.gjt.mm.mysql.Driver"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">set-property </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">="url"</span><span style="COLOR: #ff0000"> value</span><span style="COLOR: #0000ff">="jdbc:mysql://localhost/wileyusers"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">set-property </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">="maxCount"</span><span style="COLOR: #ff0000"> value</span><span style="COLOR: #0000ff">="5"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">set-property </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">="minCount"</span><span style="COLOR: #ff0000"> value</span><span style="COLOR: #0000ff">="1"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">set-property </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">="user"</span><span style="COLOR: #ff0000"> value</span><span style="COLOR: #0000ff">="sa"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">set-property </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">="password"</span><span style="COLOR: #ff0000"> value</span><span style="COLOR: #0000ff">="yourpassword"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />     </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">data-source</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">data-sources</span><span style="COLOR: #0000ff">&gt;</span></div>四、    配置FormBean<br />&lt;form-bean / &gt;用来定义将要绑定到Action的FormBean的实例。语法如下：<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: #0000ff">&lt;</span><span style="COLOR: #800000">form-beans</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />   </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">form-bean </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="name used to uniquely identify a FormBean"</span><span style="COLOR: #ff0000"> type</span><span style="COLOR: #0000ff">="fully qualified class name of FormBean"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">form-beans</span><span style="COLOR: #0000ff">&gt;</span></div><br />例：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">form-beans</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">form-bean </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="lookupForm"</span><span style="COLOR: #ff0000"> type</span><span style="COLOR: #0000ff">="wiley.LookupForm"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">form-beans</span><span style="COLOR: #0000ff">&gt;</span></div><br />五、    配置全局转发<br />全局转发可以定义几个&lt;forward/&gt;子元素，struts首先会在&lt;action-mappings&gt;元素中找对应的&lt;forward&gt;，若找不到，则到全局转发配置中找。语法如下：<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: #0000ff">&lt;</span><span style="COLOR: #800000">global-forwards</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">forward </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="unique target identifier"</span><span style="COLOR: #ff0000">  path</span><span style="COLOR: #0000ff">="context-relative path to targetted resource "</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">global-forwards</span><span style="COLOR: #0000ff">&gt;</span></div>除了name及path属性之外，还有一个redirect属性，如果redirect设为true的时候，则用HttpServletResponse.sendRedirect()方法，否则用RequestDispatcher.forward()方法，缺省为false。<br />注：如果为true，则用HttpServletResponse.sendRedirect()方法，此时存储在原来的HttpServletRequest中的值将会丢失。<br />例子：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">global-forwards</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">forward </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="success"</span><span style="COLOR: #ff0000"> path</span><span style="COLOR: #0000ff">="/welcome.jsp"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">forward </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="failure"</span><span style="COLOR: #ff0000"> path</span><span style="COLOR: #0000ff">="/index.jsp"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">global-forwards</span><span style="COLOR: #0000ff">&gt;</span></div><br />六、    配置&lt;action-mappings&gt;<br />它可以定义几个&lt;action / &gt;子元素，它主要是定义Action实例到ActionServlet类中，语法如下：<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: #0000ff">&lt;</span><span style="COLOR: #800000">action-mappings</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">action </span><span style="COLOR: #ff0000">path</span><span style="COLOR: #0000ff">="context-relative path mapping action to a request" </span><span style="COLOR: #ff0000">type</span><span style="COLOR: #0000ff">="fully qualified class name of the Action class" </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="the name of the form bean bound to this Action"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">forward </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="forwardname1"</span><span style="COLOR: #ff0000"> path</span><span style="COLOR: #0000ff">="context-relative path"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">forward </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="forwardname2"</span><span style="COLOR: #ff0000"> path</span><span style="COLOR: #0000ff">="context-relative path"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">action</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">action-mappings</span><span style="COLOR: #0000ff">&gt;</span></div>&lt;action/&gt;属性及其描述信息如下：<br />属  性    描 述 信 息<br />Path    在浏览器的URL中输入的字符(必须的)<br />Type    连结到本映射的Action的全称(可选的)<br />Name    与本操作关联的Action Bean在&lt;form-bean/&gt;中定义name名(可选的)<br />Scope    指定ActionForm Bean的作用域(session和request)，缺省为session。(可选的)<br />Input    当Bean发生错误时返回的控制。(可选的)<br />ClassName    指定一个调用这个Action类的ActionMapping类的全名。缺省用org.apache.struts.action.ActionMapping，(可选的)<br />Forward    指定处理相应请求所对应的JSP页面。(可选的)<br />Include    如果没有forward的时候，它起forward的作用。(可选的)<br />Validate    若为true，则会调用ActionForm的validate()方法，否则不调用，缺省为true。（可选的）<br />例子：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">action-mappings</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">action </span><span style="COLOR: #ff0000">path</span><span style="COLOR: #0000ff">="/lookupAction" </span><span style="COLOR: #ff0000"> type</span><span style="COLOR: #0000ff">="wiley.LookupAction" </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="LookupForm" </span><span style="COLOR: #ff0000">scope</span><span style="COLOR: #0000ff">="request" </span><span style="COLOR: #ff0000">validate</span><span style="COLOR: #0000ff">="true" </span><span style="COLOR: #ff0000">input</span><span style="COLOR: #0000ff">="/index.jsp"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">forward </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="success"</span><span style="COLOR: #ff0000"> path</span><span style="COLOR: #0000ff">="/quote.jsp"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">forward </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="faliue"</span><span style="COLOR: #ff0000"> path</span><span style="COLOR: #0000ff">="/index.jsp"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">action</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">action-mappings</span><span style="COLOR: #0000ff">&gt;</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: #0000ff">&lt;</span><span style="COLOR: #800000">action  </span><span style="COLOR: #ff0000">path</span><span style="COLOR: #0000ff">="/customer/customer"</span><span style="COLOR: #ff0000"> <font color="#008000">//路径的匹配模式</font>                                      <br />type</span><span style="COLOR: #0000ff">="com.demo.order.actions.CustomerAction"</span><span style="COLOR: #ff0000">   <font color="#008000">//满足上面路径模式的提交的请求有这个Action来响应，即有它来处理</font><br />name</span><span style="COLOR: #0000ff">="customerForm"</span><span style="COLOR: #ff0000"> <font color="#008000">//上面的路径提交的数据存放在这个formBean给上面的Action处理</font><br />parameter</span><span style="COLOR: #0000ff">="method"</span><span style="COLOR: #ff0000">  <br />input</span><span style="COLOR: #0000ff">="add"</span><span style="COLOR: #ff0000"><br />unknown</span><span style="COLOR: #0000ff">="false"</span><span style="COLOR: #ff0000"><br />validate</span><span style="COLOR: #0000ff">="true"</span><span style="COLOR: #ff0000"> <font color="#008000">//把数据保存到FormBean时是否调用上面那个FormBean的validate函数进行数据验证！</font><br /></span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">forward  </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="view"</span><span style="COLOR: #ff0000"> path</span><span style="COLOR: #0000ff">="model.customer.view" /</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"> <font color="#008000">//Action处理完后通过Forward name后面的字符串来跳转到它相应的path指定的页面</font></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">forward  </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="add"</span><span style="COLOR: #ff0000"> path</span><span style="COLOR: #0000ff">="model.customer.add" /</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">forward  </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="list"</span><span style="COLOR: #ff0000"> path</span><span style="COLOR: #0000ff">="model.customer.list" /</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">action</span><span style="COLOR: #0000ff">&gt;</span></div>七、    配置RequestProcessor<br />在struts-config.xml文件中用&lt;controller/&gt;子元素来定义RequestProcessor，其语法格式如下：<br />&lt;controller processorClass="fully qualified class name" /&gt;<br />&lt;controller /&gt;元素属性及其描述信息如下：<br />属  性    描  述<br />processorClass    指定自定义的RequestProcessor类的全名<br />BufferSize    指定用来下载所用的缓存大小。缺省是4096字节。<br />contentType    定义response文本类型，缺省是text/html<br />Debug    定义当前系统的除错级别，缺省是0<br />Locale    如果是true，则在用户的session中存放Locale对象，缺省为true<br />maxFileSize    指定下载文件最大的大小。缺省是250M<br />multipartClass    指定去代替org.apache.struts.upload.DiskMultipartRequestHandler类的类的全名。<br />Nocache    如果是true，则会关闭每个response的缓存功能。缺省是false<br />TempDir    指定上载文件所用的临时目录。缺省值由容器决定<br />例子：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">① </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">controller </span><span style="COLOR: #ff0000">processorClass</span><span style="COLOR: #0000ff">="wiley.WileyRequestProcessor"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />② </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">controller<br />    </span><span style="COLOR: #ff0000">contentType</span><span style="COLOR: #0000ff">="text/html;charset=UTF-8"</span><span style="COLOR: #ff0000"><br />    debug</span><span style="COLOR: #0000ff">="3"</span><span style="COLOR: #ff0000"><br />    locale</span><span style="COLOR: #0000ff">="true"</span><span style="COLOR: #ff0000"><br />    nocache</span><span style="COLOR: #0000ff">="true"</span><span style="COLOR: #ff0000"><br />    processorClass</span><span style="COLOR: #0000ff">="org.apache.struts.action.RequestProcessor"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span></div><br />八、    配置Message Resources<br />在struts-config.xml文件中用&lt;message-resources /&gt;元素来定义消息资源。其语法如下：<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: #0000ff">&lt;</span><span style="COLOR: #800000">message-resources  </span><span style="COLOR: #ff0000">parameter</span><span style="COLOR: #0000ff">="wiley.ApplicationResources"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">message-resources </span><span style="COLOR: #0000ff">/&gt;</span></div>元素属性及其描述信息如下：<br />属  性    描  述<br />Parameter    给定资源文件全名<br />ClassName    定义处理消息资源的类名的全名，缺省是org.apache.struts.config.MessageResourcesConfig<br />Factory    定义MessageResourcesFactory类的全名，缺省是org.apache.struts.util.property.MessageResourcesFacotry<br />Key    定义绑定在这个资源包中的ServletContext的属性主键，缺省值是Action.MESSAGES_KEY.<br />Null    如果为true，则找不到消息key时，则返回null，缺省是true.<br />例子：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">① </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">message-resources </span><span style="COLOR: #ff0000">parameter</span><span style="COLOR: #0000ff">="wiley.ApplicationResources"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />② </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">message-resources<br />    </span><span style="COLOR: #ff0000">parameter</span><span style="COLOR: #0000ff">="StorefrontMessageResources"</span><span style="COLOR: #ff0000"><br />    null</span><span style="COLOR: #0000ff">="false"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">message-resources<br />    </span><span style="COLOR: #ff0000">key</span><span style="COLOR: #0000ff">="IMAGE_RESOURCE_KEY"</span><span style="COLOR: #ff0000"><br />    parameter</span><span style="COLOR: #0000ff">="StorefrontImageResources"</span><span style="COLOR: #ff0000"><br />    null</span><span style="COLOR: #0000ff">="false"</span><span style="COLOR: #0000ff">/&gt;</span></div><br />注意：设定key的目的如下：<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: #0000ff">&lt;</span><span style="COLOR: #800000">html:img </span><span style="COLOR: #ff0000">altKey</span><span style="COLOR: #0000ff">="navbar.home.image.alt"</span><span style="COLOR: #ff0000"> bundle</span><span style="COLOR: #0000ff">="IMAGE_RESOURCE_KEY"</span><span style="COLOR: #ff0000"> pageKey</span><span style="COLOR: #0000ff">="navbar.home.image"</span><span style="COLOR: #ff0000"> width</span><span style="COLOR: #0000ff">="125"</span><span style="COLOR: #ff0000"> height</span><span style="COLOR: #0000ff">="15"</span><span style="COLOR: #ff0000"> border</span><span style="COLOR: #0000ff">="0"</span><span style="COLOR: #0000ff">/&gt;</span></div>这里说明要到StorefrontImageResources.properties资源文件中找主键值是”navbar.home.image”所对应的值。<br />这里StorefrontImageResources.properties的内容如下：<br />……<br />navbar.home.image=/images/home.gif<br />navbar.home.image.alt=Home<br />……<br />此处navbar.home.image.alt说明的和&lt;img alt=”Home”……/&gt;一样。<br />九、    配置Plug-in<br />详细学习可参考：<a href="/yesjoy/articles/106419.html">http://www.blogjava.net/yesjoy/articles/106419.html</a><br />配置Plug-in如下：<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: #0000ff">&lt;</span><span style="COLOR: #800000">plug-in </span><span style="COLOR: #ff0000">className</span><span style="COLOR: #0000ff">="wiley.WileyPlugin"</span><span style="COLOR: #0000ff">/&gt;</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: #0000ff">&lt;</span><span style="COLOR: #800000">plug-in </span><span style="COLOR: #ff0000">className</span><span style="COLOR: #0000ff">="com.oreilly.struts.storefront.service.memory.StorefrontMemoryDatabasePlugIn"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />  </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">set-property </span><span style="COLOR: #ff0000">property</span><span style="COLOR: #0000ff">="pathname"</span><span style="COLOR: #ff0000"> value</span><span style="COLOR: #0000ff">="/WEB-INF/database.xml"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">plug-in</span><span style="COLOR: #0000ff">&gt;</span></div><img src ="http://www.blogjava.net/yesjoy/aggbug/36057.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yesjoy/" target="_blank">★yesjoy★</a> 2006-03-19 13:56 <a href="http://www.blogjava.net/yesjoy/articles/36057.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Struts framework的工作原理和组件（Struts学习笔记之四）</title><link>http://www.blogjava.net/yesjoy/articles/33707.html</link><dc:creator>★yesjoy★</dc:creator><author>★yesjoy★</author><pubDate>Sun, 05 Mar 2006 07:10:00 GMT</pubDate><guid>http://www.blogjava.net/yesjoy/articles/33707.html</guid><wfw:comment>http://www.blogjava.net/yesjoy/comments/33707.html</wfw:comment><comments>http://www.blogjava.net/yesjoy/articles/33707.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yesjoy/comments/commentRss/33707.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yesjoy/services/trackbacks/33707.html</trackback:ping><description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 28pt; mso-char-indent-count: 2.0"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">对于<SPAN lang=EN-US>Struts </SPAN>如何控制、处理客户请求，让我们通过对<SPAN lang=EN-US>struts</SPAN>的四个核心组件介绍来具体说明。这几个组件就是：<SPAN lang=EN-US>ActionServlet、</SPAN><SPAN lang=EN-US>Action Classes、</SPAN><SPAN lang=EN-US>Action Mapping</SPAN>（此处包括<SPAN lang=EN-US>ActionForward</SPAN>）、<SPAN lang=EN-US>ActionForm Bean</SPAN>。<BR></P>
<H2 style="MARGIN: 13pt 0cm"><A name=_Toc65638976><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体">Struts ActionServlet</SPAN></A><SPAN style="mso-bookmark: _Toc65638976"><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-style: italic">控制器对象</SPAN></SPAN><SPAN style="mso-bookmark: _Toc65638976"></SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></H2>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 28pt; mso-char-indent-count: 2.0"><BR></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">ActionServlet</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">继承自<SPAN lang=EN-US>javax.servlet.http.HttpServlet</SPAN>类，其在<SPAN lang=EN-US>Struts framework</SPAN>中扮演的角色是中心控制器。</SPAN><SPAN style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">它提供一个中心位置来处理全部的终端请求。</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">控制器<SPAN lang=EN-US>ActionServlet</SPAN>主要负责将<SPAN lang=EN-US>HTTP</SPAN>的客户请求信息组装后，根据配置文件的指定描述，转发到适当的处理器。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">按照<SPAN lang=EN-US>Servelt</SPAN>的标准，所有得<SPAN lang=EN-US>Servlet</SPAN>必须在<SPAN lang=EN-US>web</SPAN>配置文件（<SPAN lang=EN-US>web.xml</SPAN>）声明。同样，<SPAN lang=EN-US>ActoinServlet</SPAN>必须在<SPAN lang=EN-US>Web Application</SPAN>配置文件（<SPAN lang=EN-US>web.xml</SPAN>）中描述，有关配置信息如下。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 31.5pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 3.0gd; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">&lt;servlet&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 31.5pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 3.0gd; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">&lt;servlet-name&gt;action&lt;/servlet-name&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 31.5pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 3.0gd; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">&lt;servlet-class&gt;org.apache.struts.action.ActionServlet&lt;/servlet-class&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 31.5pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 3.0gd; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">&lt;/servlet&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">全部的请求<SPAN lang=EN-US>URI</SPAN>以<SPAN lang=EN-US>*.do</SPAN>的模式存在并映射到这个<SPAN lang=EN-US>servlet</SPAN>，其配置如下：<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 10.5pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">&lt;servlet-mapping&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 31.5pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 3.0gd; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">&lt;servlet-name&gt;action&lt;/servlet-name&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 31.5pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 3.0gd; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">&lt;url-pattern&gt;*.do&lt;/url-pattern&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 31.5pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 3.0gd; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">&lt;/servlet-mapping&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">一个该模式的请求<SPAN lang=EN-US>URI</SPAN>符合如下格式：<SPAN lang=EN-US> <o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>http://www.my_site_name.com/mycontext/actionName.do<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-style: italic">中心控制器为所有的表示层请求提供了一个集中的访问点。</SPAN><SPAN style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">这个控制器提供的抽象概念减轻了开发者建立公共应用系统服务的困难，如管理视图、会话及表单数据。它也提供一个通用机制如错误及异常处理，导航，国际化，数据验证，数据转换等。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">当用户向服务器端提交请求的时候，实际上信息是首先发送到控制器<SPAN lang=EN-US>ActionServlet</SPAN>，一旦控制器获得了请求，其就会将请求信息传交给一些辅助类（<SPAN lang=EN-US>help classes</SPAN>）处理。这些辅助类知道如何去处理与请求信息所对应的业务操作。在<SPAN lang=EN-US>Struts</SPAN>中，这个辅助类就是<SPAN lang=EN-US>org.apache.struts.action.Action</SPAN>。通常开发者需要自己继承<SPAN lang=EN-US>Aciton</SPAN>类，从而实现自己的<SPAN lang=EN-US>Action</SPAN>实例。<BR></P>
<H2 style="MARGIN: 13pt 0cm"><A name=_Toc65638977><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体">Struts Action Classes</SPAN></A><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体"> <o:p></o:p></SPAN></H2>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><BR><SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">ActionServlet</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">把</SPAN><SPAN style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">全部提交的请求都被控制器委托到<SPAN lang=EN-US>RequestProcessor</SPAN>对象。<SPAN lang=EN-US>RequestProcessor</SPAN>使用<SPAN lang=EN-US>struts-config.xml</SPAN>文件检查请求<SPAN lang=EN-US>URI</SPAN>找到动作</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">Action</SPAN><SPAN style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">标示符。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">一个<SPAN lang=EN-US>Action </SPAN>类的角色，就像客户请求动作和业务逻辑处理之间的一个适配器（<SPAN lang=EN-US>Adaptor</SPAN>），其功能就是将请求与业务逻辑分开。这样的分离，使得客户请求和<SPAN lang=EN-US>Action</SPAN>类之间可以有多个点对点的映射。而且<SPAN lang=EN-US>Action</SPAN>类通常还提供了其它的辅助功能，比如：认证（<SPAN lang=EN-US>authorization</SPAN>）、日志（<SPAN lang=EN-US>logging</SPAN>）和数据验证（<SPAN lang=EN-US>validation</SPAN>）。<BR><SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">Action</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">最为常用的是<SPAN lang=EN-US>execute</SPAN>（）方法。（注意，以前的<SPAN lang=EN-US>perform</SPAN>方法在<SPAN lang=EN-US>struts1.1</SPAN>中已经不再支持），还有一个<SPAN lang=EN-US>execute</SPAN>（）方法，请参考<SPAN lang=EN-US>apidoc</SPAN>，在此不在说明。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><SPAN style="mso-tab-count: 1"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"><BR></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;ActionForward&nbsp;execute(ActionMapping&nbsp;mapping,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ActionForm&nbsp;form,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;javax.servlet.ServletRequest&nbsp;request,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;javax.servlet.ServletResponse&nbsp;response)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throws</SPAN><SPAN style="COLOR: #000000">&nbsp;java.io.IOException,javax.servlet.ServletException<BR></SPAN></DIV>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt" align=center>&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">当<SPAN lang=EN-US>Controller</SPAN>收到客户的请求的时候，在将请求转移到一个<SPAN lang=EN-US>Action</SPAN>实例时，如果这个实例不存在，控制器会首先创建，然后会调用这个<SPAN lang=EN-US>Action</SPAN>实例的<SPAN lang=EN-US>execute</SPAN>（）方法。<SPAN lang=EN-US>Struts Framework</SPAN>为应用系统中的每一个<SPAN lang=EN-US>Action</SPAN>类只创建一个实例。因为所有的用户都使用这一个实例，所以你必须确定你的<SPAN lang=EN-US>Action </SPAN>类运行在一个多线程的环境中。下图显示了一个<SPAN lang=EN-US>execute</SPAN>（）方法如何被访问：</SPAN><SPAN lang=EN-US><o:p><FONT face="Times New Roman" size=3>&nbsp;<BR><IMG alt="" hspace=0 src="K:\study\structs\学习笔记\pic\excute.gif" align=baseline border=0></FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">注意，客户自己继承的<SPAN lang=EN-US>Action</SPAN>子类，必须重写<SPAN lang=EN-US>execute</SPAN>（）方法，因为<SPAN lang=EN-US>Action</SPAN>类在默认情况下是返回<SPAN lang=EN-US>null</SPAN>的。</SPAN>&nbsp;</P>
<H2 style="MARGIN: 13pt 0cm"><A name=_Toc65638978><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体">Struts Action Mapping</SPAN></A><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体"><o:p></o:p></SPAN></H2>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">上面讲到了一个客户请求是如何被控制器转发和处理的，但是，控制器如何知道什么样的信息转发到什么样的<SPAN lang=EN-US>Action</SPAN>类呢？这就需要一些与动作和请求信息相对应的映射配置说明。在<SPAN lang=EN-US>struts </SPAN>中，这些配置映射信息是存储在特定的<SPAN lang=EN-US>XML</SPAN>文件（比如<SPAN lang=EN-US>struts-config.xml</SPAN>）。<SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">这些配置信息在系统启动的时候被读入内存，供<SPAN lang=EN-US>struts framework</SPAN>在运行期间使用。</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">在内存中，每一个<SPAN lang=EN-US>&lt;action&gt;</SPAN>元素都与<SPAN lang=EN-US>org.apache.struts.action.ActionMapping</SPAN>类的一个实例对应。下表就显示了一个登陆的配置映射。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><o:p></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">action-mappings</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">action&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #ff0000">path</SPAN><SPAN style="COLOR: #0000ff">="/logonAction"</SPAN><SPAN style="COLOR: #ff0000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type</SPAN><SPAN style="COLOR: #0000ff">="com.test.LogonAction"</SPAN><SPAN style="COLOR: #ff0000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name</SPAN><SPAN style="COLOR: #0000ff">="LogonForm"</SPAN><SPAN style="COLOR: #ff0000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scope</SPAN><SPAN style="COLOR: #0000ff">="request"</SPAN><SPAN style="COLOR: #ff0000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;input</SPAN><SPAN style="COLOR: #0000ff">="logoncheck.jsp"</SPAN><SPAN style="COLOR: #ff0000"><BR>validate</SPAN><SPAN style="COLOR: #0000ff">="false"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">forward&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="welcome"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;path</SPAN><SPAN style="COLOR: #0000ff">="/welcome.jsp"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">forward&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="failure"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;path</SPAN><SPAN style="COLOR: #0000ff">="/logon_failure.jsp&nbsp;"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">action</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">action-mappings</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN></DIV>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">上面的配置表示：当可以通过<SPAN lang=EN-US>/logonAction.do</SPAN>（此处假设配置的控制器映射为<SPAN lang=EN-US>*.do</SPAN>）提交请求信息的时候，控制器将信息委托<SPAN lang=EN-US>com.test.LogonAction</SPAN>处理。调用<SPAN lang=EN-US>LogonAction</SPAN>实例的<SPAN lang=EN-US>execute()</SPAN>方法。同时将<SPAN lang=EN-US>Mapping</SPAN>实例和所对应的<SPAN lang=EN-US>LogonForm Bean</SPAN>信息传入。其中<SPAN lang=EN-US>name=LogonForm</SPAN>，使用的<SPAN lang=EN-US>form-bean</SPAN>元素所声明的<SPAN lang=EN-US>ActionForm Bean</SPAN>。有关<SPAN lang=EN-US>form-bean</SPAN>的申明如下显示。<BR><SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">form-beans</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">form-bean&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="LoginForm"</SPAN><SPAN style="COLOR: #ff0000"><BR>type</SPAN><SPAN style="COLOR: #0000ff">="com.test.LoginForm"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">form-beans</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN></DIV>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">&nbsp;<BR></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">元素<SPAN lang=EN-US>&lt;forward&gt;</SPAN>则表示了当<SPAN lang=EN-US>Action</SPAN>实例的<SPAN lang=EN-US>execute()</SPAN>方法运行完毕后，控制器根据<SPAN lang=EN-US>Mapping</SPAN>可将响应信息转到适当的地方。如上面显示，如果客户登陆成功，则调用<SPAN lang=EN-US>welcome forward</SPAN>，将成功信息返回到<SPAN lang=EN-US>/welcome.jsp</SPAN>页面。在你的<SPAN lang=EN-US>execute()</SPAN>方法的结尾可以使用下面的实例代码而返回<SPAN lang=EN-US>welcome forward</SPAN>。当然你的<SPAN lang=EN-US>welcome forward</SPAN>必须在<SPAN lang=EN-US>action</SPAN>元素属性中定义，正如上面所声明的那样。</SPAN></P></o:p></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><o:p><SPAN style="mso-bookmark: _Toc65638976"><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-style: italic"><FONT size=5>
<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"><STRONG><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;(mapping.findForward(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">welcome</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));</SPAN></STRONG></DIV>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">ActionForward</SPAN><SPAN style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">对象是配置对象。这些配置对象拥有独一无二的标识以允许它们按照有意义的名称如<SPAN lang=EN-US>“success”</SPAN>，<SPAN lang=EN-US>“failure”</SPAN>等来检索。<SPAN lang=EN-US>ActionForward</SPAN>对象封装了向前进的<SPAN lang=EN-US>URL</SPAN>路径且被请求处理器用于识别目标视图。<SPAN lang=EN-US>ActionForward</SPAN>对象建立自<SPAN lang=EN-US>&lt;forward&gt;</SPAN>元素位于<SPAN lang=EN-US>struts-config.xml</SPAN>。下面是一个<SPAN lang=EN-US>Struts</SPAN>中<SPAN lang=EN-US>&lt;forward&gt;</SPAN>元素例子，属于<SPAN lang=EN-US>&lt;action&gt;</SPAN>元素范围。<BR></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">action&nbsp;</SPAN><SPAN style="COLOR: #ff0000">path</SPAN><SPAN style="COLOR: #0000ff">="/editCustomerProfile"</SPAN><SPAN style="COLOR: #ff0000"><BR>type</SPAN><SPAN style="COLOR: #0000ff">="packageName.EditCustomerProfileAction"</SPAN><SPAN style="COLOR: #ff0000"><BR>name</SPAN><SPAN style="COLOR: #0000ff">="customerProfileForm"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;scope</SPAN><SPAN style="COLOR: #0000ff">="request"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">forward&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="success"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;path</SPAN><SPAN style="COLOR: #0000ff">="/MainMenu.jsp"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">forward&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="failure"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;path</SPAN><SPAN style="COLOR: #0000ff">="/CustomerService.jsp"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">action</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN></DIV>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-layout-grid-align: none" align=left></SPAN></FONT><BR></P></SPAN></SPAN><SPAN style="mso-bookmark: _Toc65638976"></SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体"><o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">基于执行请求处理器的<SPAN lang=EN-US>execute(…)</SPAN>方法的结果，当传递一个值匹配指定于<SPAN lang=EN-US>&lt;forward&gt;</SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">元素中<SPAN lang=EN-US style="COLOR: black">name</SPAN><SPAN style="COLOR: black">属性的值的时候，下一个视图可以在<SPAN lang=EN-US>execute(…)</SPAN>方法中被开发者用方便的方法<SPAN lang=EN-US>org.apache.struts.action.ActionMapping.findForward(…)</SPAN>选择。<SPAN lang=EN-US>ActionMapping.findForward(…)</SPAN>方法既从它的本地范围又从全局范围提供一个<SPAN lang=EN-US>ActionForward</SPAN>对象，该对象返回至<SPAN lang=EN-US>RequestProcessor</SPAN>以<SPAN lang=EN-US>RequestDispatcher.forward(…)</SPAN>或<SPAN lang=EN-US>response.sendRedirect(…)</SPAN>调用下一个视图。当<SPAN lang=EN-US>&lt;forward&gt;</SPAN>元素有<SPAN lang=EN-US>redirect=“false”</SPAN>属性或<SPAN lang=EN-US>redirect</SPAN>属性不存在的时候，<SPAN lang=EN-US>RequestDispatcher.forward(…)</SPAN>被执行；当<SPAN lang=EN-US>redirect=“true”</SPAN>是，将调用<SPAN lang=EN-US>sendRedirect(…)</SPAN>方法。下例举例说明了<SPAN lang=EN-US>redirect</SPAN>属性的用法：<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>&lt;forward name="success" path="/Catalog.jsp" redirect="true"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">如果<SPAN lang=EN-US>redirect=true, URL</SPAN>建立如<SPAN lang=EN-US>/<SPAN style="mso-bidi-font-style: italic">contextPath</SPAN>/<SPAN style="mso-bidi-font-style: italic">path</SPAN></SPAN>因为<SPAN lang=EN-US>HttpServletResponse.sendRedirect(…)</SPAN>中解释<SPAN lang=EN-US>URL</SPAN>采用<SPAN lang=EN-US>”/”</SPAN>开头相对于<SPAN lang=EN-US>servlet</SPAN>容器根目录。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">如果<SPAN lang=EN-US>redirect=false, URI</SPAN>建立如<SPAN lang=EN-US>/<SPAN style="mso-bidi-font-style: italic">path</SPAN></SPAN><SPAN style="mso-bidi-font-style: italic">因为</SPAN><SPAN lang=EN-US>ServletContext.getRequestDisptacher(…)</SPAN>采用虚拟目录相关<SPAN lang=EN-US>URL</SPAN>。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><o:p>&nbsp;</o:p></SPAN></P><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">在此稍稍说一下有关<SPAN lang=EN-US>global-forwards</SPAN>的概念。其在配置文件中描述了整个应用系统可以使用的<SPAN lang=EN-US>ActionForward</SPAN>，而不是仅仅是一个特定的<SPAN lang=EN-US>Action</SPAN>。<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">&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">global-forwards</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">forward&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="logout"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;path</SPAN><SPAN style="COLOR: #0000ff">="/logout.do"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">forward&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="error"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;&nbsp;path</SPAN><SPAN style="COLOR: #0000ff">="/error.jsp"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">global-forwards</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN></DIV></SPAN></o:p></SPAN></o:p></SPAN>
<H2 style="MARGIN: 13pt 0cm"><A name=_Toc65638980><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">Struts ActionForm Bean</SPAN></A><SPAN style="mso-bookmark: _Toc65638980"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt">捕获表单数据</SPAN></SPAN><SPAN style="mso-bookmark: _Toc65638980"></SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></SPAN></H2><BR>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">在上面讲解<SPAN lang=EN-US>ActionServlet</SPAN>，<SPAN lang=EN-US>Action Classes</SPAN>和<SPAN lang=EN-US>Action Mapping</SPAN>的时候，我们都提到了<SPAN lang=EN-US>ActionForm Bean</SPAN>的概念。一个应用系统的消息转移（或者说状态转移）的非持久性数据存储，是由<SPAN lang=EN-US>ActionForm Bean</SPAN>的负责保持的。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp; </SPAN>ActionForm</SPAN><SPAN style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">派生的对象用于保存请求对象的参数，因此它们和用户紧密联系。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">一个<SPAN lang=EN-US>ActionForm</SPAN>类被<SPAN lang=EN-US>RequestProcessor</SPAN>建立。这是发生在已完成向前进到一个<SPAN lang=EN-US>URL</SPAN>，该<SPAN lang=EN-US>URL</SPAN>为映射到控制器<SPAN lang=EN-US>servlet</SPAN>而不是<SPAN lang=EN-US>JSP</SPAN>和相应的动作映射指定的表单属性的。在这个情况下，如果没有在指定的活动范围内找到，<SPAN lang=EN-US>RequestProcessor</SPAN>将尝试寻找可能导致创建一个新<SPAN lang=EN-US>ActionForm</SPAN>对象的表单<SPAN lang=EN-US>bean</SPAN>。该<SPAN lang=EN-US>ActionForm</SPAN>对象在指定的活动范围内被用<SPAN lang=EN-US>&lt;action&gt;</SPAN>元素的<SPAN lang=EN-US>name</SPAN>属性找到；<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">RequestProcessor</SPAN><SPAN style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">将随后重新安排表单属性，用请求时参数填充表单，随即调用表单对象的<SPAN lang=EN-US>validate(…)</SPAN>方法以履行服务器端用户输入验证。仅当<SPAN lang=EN-US>ActionMapping</SPAN>对象中<SPAN lang=EN-US>validate</SPAN>属性被设为<SPAN lang=EN-US>true</SPAN>时，<SPAN lang=EN-US>validate(…)</SPAN>方法被调用；这就是默认的行为。<SPAN lang=EN-US>request.getParameterValues(parameterName)</SPAN>被用于得到一个<SPAN lang=EN-US>String[]</SPAN>对象，它用来表单填充；验证的结果应该是一个<SPAN lang=EN-US>ActionErrors</SPAN>对象，用<SPAN lang=EN-US>org.apache.struts.taglib.html.ErrorsTag</SPAN>来显示验证错误给用户。<SPAN lang=EN-US>ActionForm</SPAN>也可以被用于为当前用户保存即将被一个视图引用的中间模型状态。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt">当一个表单对象被<SPAN lang=EN-US>RequestProcessor</SPAN>找到，它被传递到请求处理器的<SPAN lang=EN-US>execute(…)</SPAN>方法。一个<SPAN lang=EN-US>ActionForm</SPAN>对象也可以被请求处理器建立。表单对象建立目的是提供中间模型状态给使用请求范围<SPAN lang=EN-US>JSP</SPAN>；这将确保对象不会在有效性过期后仍然存在。默认的，所有的表单都被保存为会话范围。会话中表单对象脱离有效性的存在可能导致浪费内存，同样的，请求处理器必须跟踪保存在会话中的表单对象的生命周期。一个好的捕获表单数据的实践是为横跨多用户交互的相关表单用一个单独的表单<SPAN lang=EN-US>bean</SPAN>。</SPAN><SPAN style="FONT-SIZE: 14pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ansi-language: ZH-CN">表单bean也可以在反馈的时候用来储存能够被自定义标签改变的中间模型状态。在视图中标签用法避免结合Java代码，因此要成一个好的任务划分，web生产组主要处理标志，而应用开发组主要处理Java代码。标签因素退出访问中间模型状态的逻辑；当访问嵌套的对象或当通过聚集列举时这个逻辑可能很复杂。<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">注意：在<SPAN lang=EN-US>struts1.1</SPAN>中，<SPAN lang=EN-US>ActionForm</SPAN>的校验功能，逐渐被剥离出来（当然依然可以使用）。使用了<SPAN lang=EN-US>validator framework</SPAN>对整个应用系统的表单数据验证进行统一管理。相信信息请参考：<SPAN lang=EN-US>http://home.earthlink.net/~dwinterfeldt<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">在<SPAN lang=EN-US>ActionForm</SPAN>的使用中，<SPAN lang=EN-US>Struts</SPAN>提倡使用到值对象（<SPAN lang=EN-US>Value Object</SPAN>）。这样将客户或开发人员，对数据状态与对象状态能够更加清晰的理解和使用。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">对于每一个客户请求，<SPAN lang=EN-US>Struts framework</SPAN>在处理<SPAN lang=EN-US>ActionForm</SPAN>的时候，一般需要经历如下几个步骤：<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">（１）检查<SPAN lang=EN-US>Action</SPAN>的映射，确定<SPAN lang=EN-US>Action</SPAN>中已经配置了对<SPAN lang=EN-US>ActionForm</SPAN>的映射<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">（２）根据<SPAN lang=EN-US>name</SPAN>属性，查找<SPAN lang=EN-US>form bean</SPAN>的配置信息<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">（３）检查<SPAN lang=EN-US>Action</SPAN>的<SPAN lang=EN-US>formbean</SPAN>的使用范围，确定在此范围下，是否已经有此<SPAN lang=EN-US>form bean</SPAN>的实例。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">（４）假如当前范围下，已经存在了此<SPAN lang=EN-US>form bean</SPAN>的实例，而是对当前请求来说，是同一种类型的话，那么就重用。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">（５）否则，就重新构建一个<SPAN lang=EN-US>form bean</SPAN>的实例<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">（６）<SPAN lang=EN-US>form bean</SPAN>的<SPAN lang=EN-US>reset()</SPAN>方法备调用<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">（７）调用对应的<SPAN lang=EN-US>setter</SPAN>方法，对状态属性赋值<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">（８）如果<SPAN lang=EN-US>validatede</SPAN>的属性北设置为<SPAN lang=EN-US>true</SPAN>，那么就调用<SPAN lang=EN-US>form bean</SPAN>的<SPAN lang=EN-US>validate()</SPAN>方法。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">（<SPAN lang=EN-US>9</SPAN>）如果<SPAN lang=EN-US>validate</SPAN>（）方法没有返回任何错误，控制器将<SPAN lang=EN-US>ActionForm</SPAN>作为参数，传给<SPAN lang=EN-US>Action</SPAN>实例的<SPAN lang=EN-US>execute</SPAN>（）方法并执行。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><o:p>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">注意：直接从<SPAN lang=EN-US>ActionFrom</SPAN>类继承的<SPAN lang=EN-US>reset()</SPAN>和<SPAN lang=EN-US>validate()</SPAN>方法，并不能实现什么处理功能，所以有必要自己重新覆盖。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></B></P></o:p></SPAN><img src ="http://www.blogjava.net/yesjoy/aggbug/33707.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yesjoy/" target="_blank">★yesjoy★</a> 2006-03-05 15:10 <a href="http://www.blogjava.net/yesjoy/articles/33707.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Struts的基本组件包（Struts学习笔记之三） </title><link>http://www.blogjava.net/yesjoy/articles/33703.html</link><dc:creator>★yesjoy★</dc:creator><author>★yesjoy★</author><pubDate>Sun, 05 Mar 2006 06:43:00 GMT</pubDate><guid>http://www.blogjava.net/yesjoy/articles/33703.html</guid><wfw:comment>http://www.blogjava.net/yesjoy/comments/33703.html</wfw:comment><comments>http://www.blogjava.net/yesjoy/articles/33703.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yesjoy/comments/commentRss/33703.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yesjoy/services/trackbacks/33703.html</trackback:ping><description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">整个<SPAN lang=EN-US>struts</SPAN>大约有<SPAN lang=EN-US>15</SPAN>包，近<SPAN lang=EN-US>200</SPAN>个类所组成，而且数量还在不断的扩展。在此我们不能一一介绍，只能列举几个主要的简要的介绍一下。下表说明了目前<SPAN lang=EN-US>struts api</SPAN>中基本的几个组件包，包括<SPAN lang=EN-US>action,actions,config,util,taglib,validator</SPAN>。下图则显现了这几个组件包之间的关系。其中<SPAN lang=EN-US>action</SPAN>是整个<SPAN lang=EN-US>struts framework</SPAN>的核心<SPAN lang=EN-US><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></SPAN></P>
<DIV align=center>
<TABLE class=MsoNormalTable style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; MARGIN: auto auto auto 41.4pt; BORDER-LEFT: medium none; WIDTH: 385pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=513 border=1>
<TBODY>
<TR style="HEIGHT: 7.5pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 385pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 7.5pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=513>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">org.apache.struts.action</SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><o:p></o:p></SPAN></P></TD></TR>
<TR style="HEIGHT: 15.75pt; mso-yfti-irow: 1">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 385pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 15.75pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=513>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">基本上，控制整个<SPAN lang=EN-US>struts framework</SPAN>的运行的核心类、组件都在这个包中，比如我们上面提到的控制器<SPAN lang=EN-US>ActionServlet</SPAN>。已经<SPAN lang=EN-US>Action,ActionForm,ActionMapping</SPAN>等等。<SPAN lang=EN-US>struts1.1</SPAN>比<SPAN lang=EN-US>1.0</SPAN>多了<SPAN lang=EN-US> DynaActionForm </SPAN>类。增加了动态扩展生成<SPAN lang=EN-US>FormBean</SPAN>功能<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P></TD></TR>
<TR style="HEIGHT: 15.75pt; mso-yfti-irow: 2">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 385pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 15.75pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=513>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">org.apache.struts.actions</SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><o:p></o:p></SPAN></P></TD></TR>
<TR style="HEIGHT: 15.75pt; mso-yfti-irow: 3">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 385pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 15.75pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=513>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">这个包是主要作用是提供客户的<SPAN lang=EN-US>http</SPAN>请求和业务逻辑处理之间的特定适配器转换功能，而<SPAN lang=EN-US>1.0</SPAN>版本中的部分动态增删<SPAN lang=EN-US>FromBean</SPAN>的类，也在<SPAN lang=EN-US>struts1.1</SPAN>中被<SPAN lang=EN-US>Action</SPAN>包的<SPAN lang=EN-US>DynaActionForm</SPAN>组件所取代<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P></TD></TR>
<TR style="HEIGHT: 15.75pt; mso-yfti-irow: 4">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 385pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 15.75pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=513>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">org.apache.struts.config<o:p></o:p></SPAN></B></P></TD></TR>
<TR style="HEIGHT: 15.75pt; mso-yfti-irow: 5">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 385pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 15.75pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=513>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">提供对配置文件<SPAN lang=EN-US>struts-config.xml</SPAN>元素的映射。这也是<SPAN lang=EN-US>sturts1.1</SPAN>中新增的功能<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P></TD></TR>
<TR style="HEIGHT: 15.75pt; mso-yfti-irow: 6">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 385pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 15.75pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=513>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">org.apache.struts.util</SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><o:p></o:p></SPAN></P></TD></TR>
<TR style="HEIGHT: 15.75pt; mso-yfti-irow: 7">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 385pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 15.75pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=513>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">Strtuts</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">为了更好支持<SPAN lang=EN-US>web application</SPAN>的应用，体统了一个些常用服务的支持，比如<SPAN lang=EN-US>Connection Pool</SPAN>和<SPAN lang=EN-US>Message Source</SPAN>。详细信息请参考<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">http://jakarta.apache.org/struts/api/org/apache/struts/util/package-summary.html<o:p></o:p></SPAN></P></TD></TR>
<TR style="HEIGHT: 15.75pt; mso-yfti-irow: 8">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 385pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 15.75pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=513>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">org.apache.struts.taglib</SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><o:p></o:p></SPAN></P></TD></TR>
<TR style="HEIGHT: 15.75pt; mso-yfti-irow: 9">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 385pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 15.75pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=513>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">这不是一个包，而是是一个客户标签类的集合。下面包括<SPAN lang=EN-US>Bean Tags</SPAN>，<SPAN lang=EN-US>HTML Tags</SPAN>，<SPAN lang=EN-US>Logic Tags</SPAN>，<SPAN lang=EN-US>Nested Tags</SPAN>，<SPAN lang=EN-US>Template Tags</SPAN>这几个用于构建用户界面的标签类。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P></TD></TR>
<TR style="HEIGHT: 15.75pt; mso-yfti-irow: 10">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 385pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 15.75pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=513>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">org.apache.struts.validator</SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><o:p></o:p></SPAN></P></TD></TR>
<TR style="HEIGHT: 15.75pt; mso-yfti-irow: 11; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 385pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 15.75pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=513>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">Struts1.1 framework</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">中增加了<SPAN lang=EN-US>validator framework</SPAN>，用于动态的配置<SPAN lang=EN-US>from</SPAN>表单的验证。详细信息请参阅 <SPAN lang=EN-US>http://home.earthlink.net/~dwinterfeldt/<B><o:p></o:p></B></SPAN></SPAN></P></TD></TR></TBODY></TABLE><BR></DIV>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt" align=center><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体"><o:p>&nbsp;<IMG alt="" hspace=0 src="K:\study\structs\学习笔记\pic\api.gif" align=baseline border=0><BR></o:p></SPAN></P><img src ="http://www.blogjava.net/yesjoy/aggbug/33703.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yesjoy/" target="_blank">★yesjoy★</a> 2006-03-05 14:43 <a href="http://www.blogjava.net/yesjoy/articles/33703.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Struts的概念和体系结构（Struts学习笔记之二）</title><link>http://www.blogjava.net/yesjoy/articles/33672.html</link><dc:creator>★yesjoy★</dc:creator><author>★yesjoy★</author><pubDate>Sun, 05 Mar 2006 03:52:00 GMT</pubDate><guid>http://www.blogjava.net/yesjoy/articles/33672.html</guid><wfw:comment>http://www.blogjava.net/yesjoy/comments/33672.html</wfw:comment><comments>http://www.blogjava.net/yesjoy/articles/33672.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yesjoy/comments/commentRss/33672.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yesjoy/services/trackbacks/33672.html</trackback:ping><description><![CDATA[<SPAN lang=EN-US style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p><FONT size=3>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 12pt">Struts</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是一个</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt">Web <A HREF="/yesjoy/articles/33670.html"><FONT color=#023264>Framework</FONT></A></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt">struts</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">开始于</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt">2000</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">年３月，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt">1.0</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt">2001</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">年</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt">7</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">月发布。采用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt">Struts</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">能开发出基于</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt">MVC(Model-View-Controller)</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设计模式的应用构架。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt">MVC</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设计模式把一个系统分成</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt">3</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个相互协调的部分。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt">struts framework</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt">MVC </SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">模式的体现，下面我们就从分别从模型、视图、控制来看看</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt">struts</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的体系结构（</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt">Architecture</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）。</SPAN><BR>在基于JSP/Servlet的Web应用中要使用MVC模式，需要解决一个问题。我们知道，HTTP的底层是TCP/IP协议，而TCP/IP是一种无状态连接的协议，那么如果我们的模型发生了变化，就无从通知视图。Struts采用了在“JSP规范&nbsp;v0.92”中提到的MVC&nbsp;Model&nbsp;2，这是对MVC在Web上应用的修订版。图示如下：</FONT><BR><BR><IMG alt="" hspace=0 src="file:///K:/study/structs/学习笔记/pic/strutsFrame1.bmp" align=baseline border=0><BR></o:p></SPAN><FONT size=3>图表&nbsp;1：MVC&nbsp;Model&nbsp;2（From&nbsp;Malcolm&nbsp;Davis）<BR></FONT><BR><FONT size=3><STRONG>Model（模型）<BR></STRONG>模型用于封装系统的状态。</FONT><FONT size=3><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">在</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">Struts</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">中，系统模型的状态主要由</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">ActiomForm Bean</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">和值对象体现。</SPAN></FONT><BR><BR><FONT size=3><B>View（视图）</B><BR>是模型的表示，提供用户交互界面。当模型状态发生变化时，视图应该得到通知，以便更新视图。<BR></FONT><FONT size=3><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">首先，</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">Struts</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">提供了</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">Java</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">类</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">org. apache.struts.action.ActionForm</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">Java</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">开发者将该类细分来创建表单</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">bean</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">。在运行时，该</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">bean</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">有两种用法：<BR></SPAN></FONT><FONT size=3><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ―<SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">当</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">JSP</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">准备相关的</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">HTML</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">表单以进行显示时，</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">JSP</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">将访问该</SPAN></FONT><FONT size=3><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">bean(</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">它保存要放入表单中的值</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">)</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">。那些值是从业务逻辑或者是从先前的用户输入来提供的。<BR></SPAN></FONT><FONT size=3><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ―<SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">当从</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">Web</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">浏览器中返回用户输入时，该</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">bean</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">将验证并保存该输入以供业务逻辑或</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">(</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">如果验证失败的话</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">)</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">后续重新显示使用。<BR></SPAN></FONT><FONT size=3><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">其次，</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">Struts</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">提供了许多定制</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">JSP</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">标记，它们的使用简单，但是它们在隐藏信息方面功能强大。例如，除了</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">bean</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">名称和给定</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">bean</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">中每个段的名称之外，页面设计者不需要知道有关表单</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">bean</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'">的更多信息。<BR><BR></SPAN></FONT><FONT size=3><B>Controller（控制器）</B><BR>接受来自视图的请求，修改模型的状态。<SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">Struts framework</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">中，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"> Controller</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">主要是</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">ActionServlet</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">，但是对于业务逻辑的操作则主要由</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">Action</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">、</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">ActionMapping</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">、</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">ActionForward</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">这几个组件协调完成（也许这几个组件，应该划分到模型中的业务逻辑一块）。其中，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">Action</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">扮演了真正的控制逻辑的实现者，而</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">ActionMapping</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">和</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">ActionForward</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">则指定了不同业务逻辑或流程的运行方向。<BR><BR><STRONG>下面从系统的角度简单介绍一下Struts的工作原理：</STRONG><BR><FONT face="Times New Roman">Struts应用有3个主要部件：一个Servlet&nbsp;Controller（由Struts提供，org.apache.action.ActionServlet，以下简称controller）及负责具体业务处理的Action类（org.apache.action.Action的基类）；Jsp页面（viewer）；应用的业务逻辑封装（model）。Struts&nbsp;的中心控制器（ActionServlet）接受所有来自客户端的请求，并根据系统的配置（Struts-config.xml）路由HTTP请求到其他Action对象（开发者实现的org.apache.struts.action.Action的子类），在这些Action对象中会进行所有的业务操作，比如插入一条订单，修改一条记录。处理完毕，由Struts的ActionServlet转向到JSP页面，将处理结果返回给客户端。从这儿可以看出在Struts中ActionServlet担任了重要的角色，由它控制所有的程序流转，是MVC三个相对独立的部分协调工作，提供系统的完善功能。从下图可见Struts是MVC&nbsp;Model&nbsp;2的一个典型应用。<BR></FONT></P></SPAN></FONT></SPAN><IMG alt="" hspace=0 src="file:///K:/study/structs/学习笔记/pic/strutsFrame2.bmp" align=baseline border=0><BR>图表&nbsp;2：Struts工作机理（From&nbsp;Malcolm&nbsp;Davis）<BR><BR>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">在<SPAN lang=EN-US>Struts</SPAN>启动时，<SPAN lang=EN-US>controller</SPAN>会读入一个配置文件<SPAN lang=EN-US>struts-config.xml</SPAN>，其中定义了前端请求的<SPAN lang=EN-US>url</SPAN>与相应的<SPAN lang=EN-US>Action</SPAN>类及使用的<SPAN lang=EN-US>Form</SPAN>类的映射关系，下面是一个<SPAN lang=EN-US>struts-config.xml</SPAN>中的片断：</SPAN><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">&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">action&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #ff0000">path</SPAN><SPAN style="COLOR: #0000ff">="/logon"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type</SPAN><SPAN style="COLOR: #0000ff">="org.apache.struts.webapp.example.LogonAction"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name</SPAN><SPAN style="COLOR: #0000ff">="logonForm"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scope</SPAN><SPAN style="COLOR: #0000ff">="request"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;input</SPAN><SPAN style="COLOR: #0000ff">="/logon.jsp"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">action</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR></SPAN></DIV>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">从中可以看出，这个<SPAN lang=EN-US>action</SPAN>会响应<SPAN lang=EN-US>url</SPAN>类似于<SPAN lang=EN-US>/logon</SPAN>的请求（在后面我们会看到，这儿的实际的<SPAN lang=EN-US>url</SPAN>要根据在<SPAN lang=EN-US>web.xml</SPAN>中配置，比如可能为<SPAN lang=EN-US>/logon.do</SPAN>或<SPAN lang=EN-US>/logon.other</SPAN>之类的带后缀的<SPAN lang=EN-US>url</SPAN>），负责处理这个请求的<SPAN lang=EN-US>action</SPAN>类是<SPAN lang=EN-US>org.apache.struts.webapp.example.LogonAction</SPAN>，使用的<SPAN lang=EN-US>FormBean</SPAN>是<SPAN lang=EN-US>logonForm</SPAN>，<SPAN lang=EN-US>scope</SPAN>界定了这个<SPAN lang=EN-US>FormBean</SPAN>存在的范围是只在当前<SPAN lang=EN-US>request</SPAN>中存在。<SPAN lang=EN-US><BR>struts</SPAN>会读入这些设置，生成相应的<SPAN lang=EN-US>org.apache.action.ActionMapping</SPAN>对象。<SPAN lang=EN-US>controller</SPAN>正是使用这些<SPAN lang=EN-US>mapping</SPAN>来把<SPAN lang=EN-US>HTTP</SPAN>请求转发到应用的<SPAN lang=EN-US>actions</SPAN>。一个<SPAN lang=EN-US>ActionMapping</SPAN>指定了</SPAN><BR></P>
<UL type=disc>
<LI class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">一个请求<SPAN lang=EN-US>URI<o:p></o:p></SPAN></SPAN></LI>
<LI class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">对应的类（<SPAN lang=EN-US>Action</SPAN>的子类）<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></LI>
<LI class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">需要的属性<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></LI></UL>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><BR></SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">对于一个<SPAN lang=EN-US>DB</SPAN>应用，<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<UL type=disc>
<LI class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l1 level1 lfo2; tab-stops: list 36.0pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">一个商业逻辑<SPAN lang=EN-US>Bean</SPAN>用于连接、查询数据库<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></LI>
<LI class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l1 level1 lfo2; tab-stops: list 36.0pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">这个<SPAN lang=EN-US>Bean</SPAN>返回结果到<SPAN lang=EN-US>Action<o:p></o:p></SPAN></SPAN></LI>
<LI class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l1 level1 lfo2; tab-stops: list 36.0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Action</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">将这些结果存储到<SPAN lang=EN-US>request</SPAN>的<SPAN lang=EN-US>form&nbsp;bean</SPAN>中<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></LI>
<LI class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l1 level1 lfo2; tab-stops: list 36.0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Jsp</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">显示<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></LI></UL>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt"><o:p>&nbsp;</o:p></SPAN>转自：<A href="http://www.javaresearch.org/article/showarticle.jsp?column=23&amp;thread=256">http://www.javaresearch.org/article/showarticle.jsp?column=23&amp;thread=256</A></P><img src ="http://www.blogjava.net/yesjoy/aggbug/33672.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yesjoy/" target="_blank">★yesjoy★</a> 2006-03-05 11:52 <a href="http://www.blogjava.net/yesjoy/articles/33672.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Framework概念（Struts学习笔记之一）</title><link>http://www.blogjava.net/yesjoy/articles/33670.html</link><dc:creator>★yesjoy★</dc:creator><author>★yesjoy★</author><pubDate>Sun, 05 Mar 2006 03:24:00 GMT</pubDate><guid>http://www.blogjava.net/yesjoy/articles/33670.html</guid><wfw:comment>http://www.blogjava.net/yesjoy/comments/33670.html</wfw:comment><comments>http://www.blogjava.net/yesjoy/articles/33670.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yesjoy/comments/commentRss/33670.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yesjoy/services/trackbacks/33670.html</trackback:ping><description><![CDATA[<SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">一直以来我们都说</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Struts</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">是一个</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Web Framework</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">。那么让我么先来看看什么是</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Framework</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; COLOR: gray; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Framework</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">概念并不是很新了，伴随着软件开发的发展，在多层的软件开发项目中，可重用、易扩展的，而且是经过良好测试的软件组件，越来越为人们所青睐。这意味着人们可以将充裕的时间用来分析、构建业务逻辑的应用上，而非繁杂的代码工程。于是人们将相同类型问题的解决途径进行抽象，抽取成一个应用框架。这也就是我们所说的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Framework</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp; </SPAN>Framework</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">的体系提供了一套明确机制，从而让开发人员很容易的扩展和控制整个</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Framework</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">开发上的结构。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">通常，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Framework</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">的结构中都有一个</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">“</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">命令和控制</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">”</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">组件（</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">"command and control" component</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">）</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">——Framework Factory and Manager</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt"><o:p>&nbsp;</o:p></SPAN><BR><STRONG><IMG alt="" hspace=0 src="file:///K:/study/structs/学习笔记/pic/framework.gif" align=baseline border=0><BR></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><STRONG><SPAN lang=EN-US style="FONT-SIZE: 18pt; FONT-FAMILY: 宋体">Framework</SPAN></STRONG><STRONG><SPAN style="FONT-SIZE: 18pt; FONT-FAMILY: 宋体">体系</SPAN></STRONG><SPAN lang=EN-US style="FONT-SIZE: 18pt; FONT-FAMILY: 宋体"><o:p></o:p></SPAN></P></STRONG></SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'">
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">通过基于请求响应（</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Request-Response</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">）模式的应用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Framework</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">，基本上有如下几个表现逻辑结构组成。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><B><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">控制器</SPAN></B><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">（</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Controller</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">）</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">——</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">控制整个</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Framework</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">中各个组件的协调工作。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><B><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">业务逻辑层</SPAN></B><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">（</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Business Logic</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">）</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">——</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">对</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Framwork</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">本身来说，这里仅仅只是概念和几个提够服务的基础组件，真正的实现与客户的业务逻辑接轨，还需要开发人员在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Framework</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">上再次扩展。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 12pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><B><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">数据逻辑层</SPAN></B><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">（</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Data Logic</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">）</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">——</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">绝大应用系统都需要涉及到数据交互，这一层次主要包括了数据逻辑和数据访问接口。对于数据逻辑来说，如果你了解数据建模（</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Data Modeling</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">）可能就很容易理解。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-char-indent-count: 2.0; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Struts</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">有一组相互协作的类、</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Serlvet</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">以及</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Jsp TagLib</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">组成。基于</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Struts</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">构架的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">web</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">应用程序基本上符合</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">JSP Model2</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">的设计标准，可以说是</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">MVC</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">设计模式的一种变化类型。根据上面对</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">framework</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">的描述，我们很容易理解为什么说</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Struts</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">是一个</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">web framwork</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">，而不仅仅是一些标记库的组合。但</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"> Struts </SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">也包含了丰富的标记库和独立于该框架工作的实用程序类。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 28pt; TEXT-ALIGN: left; mso-char-indent-count: 2.0; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Struts</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">有其自己的控制器（</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Controller</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">），同时整合了其他的一些技术去实现模型层（</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Model</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">）和视图层（</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">View</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">）。在模型层，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Struts</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">可以很容易的与数据访问技术相结合，包括</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">EJB,JDBC</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">和</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Object Relation Bridge</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">。在视图层，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Struts</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">能够与</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">JSP, Velocity Templates,XSL</SPAN><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">等等这些表示层组件想结合。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 14pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN><BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><o:p></o:p></SPAN></P>
<H2 style="MARGIN: 13pt 0cm"><A name=_Toc65638969><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体">Struts</SPAN></A><SPAN style="mso-bookmark: _Toc65638969"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'">的与</SPAN></SPAN><SPAN style="mso-bookmark: _Toc65638969"><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体">Web App</SPAN></SPAN><SPAN style="mso-bookmark: _Toc65638969"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'">的关系</SPAN></SPAN><SPAN style="mso-bookmark: _Toc65638969"></SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体"><o:p></o:p></SPAN></H2>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><o:wrapblock><?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><v:shapetype id=_x0000_t75 coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></v:path><o:lock v:ext="edit" aspectratio="t"></o:lock></v:shapetype><v:shape id=_x0000_s1026 style="MARGIN-TOP: 46.8pt; Z-INDEX: 1; LEFT: 0px; MARGIN-LEFT: 1in; WIDTH: 270pt; POSITION: absolute; HEIGHT: 184.85pt; TEXT-ALIGN: left" type="#_x0000_t75"><FONT size=5><v:imagedata grayscale="t" blacklevel="1966f" cropright="14135f" o:href="figures/str_0202.bmp" src="file:///C:\DOCUME~1\yesjoy\LOCALS~1\Temp\msohtml1\01\clip_image001.png"></v:imagedata><?xml:namespace prefix = w ns = "urn:schemas-microsoft-com:office:word" /><w:wrap type="topAndBottom"></w:wrap></FONT></v:shape></o:wrapblock><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'"></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体">既然<SPAN lang=EN-US>struts</SPAN>叫做<SPAN lang=EN-US>web framework</SPAN>，那么其肯定主要基于<SPAN lang=EN-US>web</SPAN>层的应用系统开发。按照<SPAN lang=EN-US>J2EE Architecture</SPAN>的标准，<SPAN lang=EN-US>struts</SPAN>应当和<SPAN lang=EN-US>jsp/servlet</SPAN>一样，存在于<SPAN lang=EN-US>web container</SPAN>一层。<BR><SPAN lang=EN-US><o:p><IMG alt="" hspace=0 src="K:\study\structs\学习笔记\pic\webapp.gif" align=baseline border=0></o:p></SPAN></SPAN></P></SPAN></o:p></SPAN><img src ="http://www.blogjava.net/yesjoy/aggbug/33670.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yesjoy/" target="_blank">★yesjoy★</a> 2006-03-05 11:24 <a href="http://www.blogjava.net/yesjoy/articles/33670.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>初学者入门：Structs中基本配置入门</title><link>http://www.blogjava.net/yesjoy/articles/31830.html</link><dc:creator>★yesjoy★</dc:creator><author>★yesjoy★</author><pubDate>Tue, 21 Feb 2006 09:33:00 GMT</pubDate><guid>http://www.blogjava.net/yesjoy/articles/31830.html</guid><wfw:comment>http://www.blogjava.net/yesjoy/comments/31830.html</wfw:comment><comments>http://www.blogjava.net/yesjoy/articles/31830.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yesjoy/comments/commentRss/31830.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yesjoy/services/trackbacks/31830.html</trackback:ping><description><![CDATA[class&gt;<BR>　　&lt;/servlet&gt;<BR>　　<BR>　　&lt;servlet-mapping&gt;<BR>　　&lt;servlet-name&gt;action&lt;/servlet-name&gt;<BR>　　&lt;uri-pattern&gt;*.do&lt;/url-pattern&gt;<BR>　　&lt;/servlet-mapping&gt;<BR>　　<BR>　　注意:不管应用中包含多少个子应用,都只需配置一个ActionServlet,因为ActionServlet支持多线程,目前的Structs框架只允许在应用中配置一个ActionServlet。<BR>　　<BR>　　第二步：初始化参数对Servlet的运行环境进行初始化配置。<BR>　　<BR>　　&lt;servlet&gt;<BR>　　&lt;servlet-name&gt;&nbsp;action&lt;/servlet-name&gt;<BR>　　&lt;servlet-class&gt;&nbsp;org.appache.structs.ActionServlet&nbsp;&lt;/servlet-class&gt;<BR>　　&lt;init-param&gt;<BR>　　&lt;param-name&gt;config&lt;/param-name&gt;<BR>　　&lt;param-value&gt;/WEB-INF/structs-config.xml&lt;/param-value&gt;<BR>　　&lt;/init-param&gt;<BR>　　&lt;/servlet&gt;<BR>　　<BR>　　表2-1.&nbsp;Struts1.1中用到的初始化参数<BR>　　<BR>　　参数名　　　　　　&nbsp;含义/默认值<BR>　　config　　　　　以相对路径的方式指明Struts应用程序的配置文件位置。如不设置，则默认值为/WEB-INF/struts-config.xml。<BR>　　config/sub1　　&nbsp;以相对路径的方式指明子应用程序的配置文件位置，一般来说，很少用到子应用程序，在此不多描述。<BR>　　debug　　　　　&nbsp;设置Servlet的debug级别，控制日志记录的详细程度。默认为0，记录相对最少的日志信息。<BR>　　detail　　　　　设置Digester的debug级别，Digester是Struts框架所使用的用来解析xml配置文件的一个框架，通过该设置，可以查看不同详细等级的解析日志。默认为0，记录相对最少的日志信息。<BR>　　<BR>　　第三步：配置欢迎清单<BR>　　<BR>　　当客户访问Web应用时，如果仅仅给出Web应用的Root&nbsp;URL，没用指定具体的文件名，Web容器会自动调用Web应用的欢迎文件。<BR>　　<BR>　　&lt;welcome-file-list&gt;<BR>　　&lt;welcome-file&gt;welcome.jsp&lt;/welcome-file&gt;<BR>　　&lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;<BR>　　&lt;/welcome-fiel-list&gt;<BR>　　<BR>　　说明：&lt;welcome-file-list&gt;可以包含多个&lt;welcome-file&gt;子元素，首先查找第一个&lt;welcome-file&gt;文件。<BR>　　<BR>　　由于&lt;welcome-file-list&gt;元素中不能配置Servlet映射，因此不能直接把Structs的Action作为欢迎文件，可以采用一种变通的方法来实现在欢迎文件中调用Structs&nbsp;Action。首先，在Structs配置文件中为被调用的Action创建一个全局的转发项，例如：<BR>　　&lt;global-forwards&gt;<BR>　　&lt;forward&nbsp;name=”welcome”&nbsp;path=”HelloWord.do”/&gt;<BR>　　&lt;/global-forwords&gt;<BR>　　<BR>　　创建一个welcome.jsp的文件<BR>　　<BR>　　最后在web.xml文件中把welcome.jsp文件配置为欢迎文件，代码如下：<BR>　　&lt;welcome-file-list&gt;<BR>　　&lt;welcome-file&gt;welcome.jsp&lt;/welcome-file&gt;<BR>　　&lt;/welcome-file-list&gt;<BR>　　<BR>　　第四步：配置错误处理<BR>　　<BR>　　&lt;error-page&gt;<BR>　　&lt;error-code&gt;404&lt;/error-code&gt;<BR>　　&lt;location&gt;/commom/404.jsp&lt;/location&gt;<BR>　　&lt;/error-page&gt;<BR>　　&lt;error-page&gt;<BR>　　&lt;error-code&gt;505&lt;/error-code&gt;<BR>　　&lt;location&gt;/commom/505.jsp&lt;/location&gt;<BR>　　&lt;/error-page&gt;<BR>　　<BR>　　也可以为Web容器捕获的Java异常配置&lt;error-page&gt;,需要设置&lt;exception-type&gt;子元素，它用于指定Java异常类。Web容器可能捕获如下异常：<BR>　　<BR>　　RuntimeException或Error　&nbsp;ServletException或它的子类　IOException或它的子类<BR>　　<BR>　　&lt;error-page&gt;<BR>　　&lt;exception-type&gt;java.io.IOException&lt;/exception-type&gt;<BR>　　&lt;location&gt;/common/system_ioerror.jsp&lt;/location&gt;<BR>　　&lt;/error-page&gt;<BR>　　<BR>　　第五步：配置Structs标签库<BR>　　<BR>　　使用客户化的标签库，要配置它们<BR>　　<BR>　　&lt;taglib&gt;<BR>　　&lt;tag-uri&gt;/WEB-INF/structs-html.tld&lt;tag-uri&gt;<BR>　　&lt;taglib-location&gt;/WEB-INF/structs-html.tld&lt;/taglib-location&gt;<BR>　　&lt;/taglib&gt;<BR>　　<BR>　　&lt;tag-uri&gt;用于指定标签库的相对或者绝对URI地址，Web应用根据这一URI来访问标签库。<BR>　　<BR>　　&lt;taglib-location&gt;指定标签描述文件在文件资源系统中的物理位置。<BR>　　<BR>　　2.Structs配置文件<BR>　　<BR>　　Structs框架在启动时会读入其配置文件，根据它来创建和配置各种Structs组件。<BR>　　<BR>　　1&lt;Structs-config&gt;元素<BR>　　<BR>　　&lt;structs-config&gt;元素是Structs配置文件的根元素，&lt;structs-cofig&gt;元素有8个子元素。它的DTD定义如下：<BR>　　<BR>　　&lt;!ELEMENT&nbsp;structs-config(data-sources?,formbean?,global-exeception?,global-forward?,action-mapping,controller?,message-resources*,plug-in*)&gt;<BR>　　<BR>　　在Struts配置中，必须按照以上的DTD指定的先后顺序来配置&lt;Structs-config&gt;元素的各个子元素，如果颠倒了这些元素的配置文件中的位置，在Structs应用启动时会生成错误。<BR>　　<BR>　　&lt;data-sources&gt;元素<BR>　　<BR>　　&lt;data-sources&gt;元素包含零个、一个或者多个&lt;data-sources&gt;子元素，&lt;data-sources&gt;用于配置特定的数据源，它可以包含多个&lt;set-property&gt;子元素，用于设置数据源的各种属性。<BR>　　。。。<BR>　　<BR>　　配置了数据源后，就可以在Action类中访问数据源，在org.apache.structs.action.Action类中定义了getDataSource(HttpRequrst)方法，它用于获取数据源对象的引用。<BR>　　<BR>　　DataSource　dataSource;<BR>　　Connection　connection;<BR>　　dataSource&nbsp;=getDataSource(request);<BR>　　connection=dataSource.getConnection();<BR>　　<BR>　　也可以在配置文件中声明多个数据源，此时需要为每一个数据源分配唯一的key值，通过改值来标识特定的数据源。<BR>　　<BR>　　2&lt;form-beans&gt;元素<BR>　　<BR>　　&lt;form-beans&gt;元素用来配置多个ActionForm&nbsp;Bean，&lt;form-beans&gt;包含多个&lt;forom-bean&gt;子元素，,每个&lt;from-bean&gt;包含多个属性，ClassName&nbsp;,&nbsp;name,type<BR>　　<BR>　　&lt;form-beans&gt;<BR>　　&lt;form-bean&nbsp;name="HelloForm"&nbsp;type="hello.HelloForm"/&gt;<BR>　　&lt;/form-beans&gt;<BR>　　<BR>　　注意：配置动态ActionForm&nbsp;Bean，还必须配置&lt;form-bean&gt;元素的&lt;form-property&gt;元素。<BR>　　<BR>　　&lt;form-beans&gt;<BR>　　&lt;form-bean&nbsp;name="HelloForm"&nbsp;type="hello.HelloForm"/&gt;<BR>　　&lt;form-bean&nbsp;name="userForm"&nbsp;type="org.apache.structs.action.DynaAction"&gt;<BR>　　&lt;from-property&nbsp;name="firstname"&nbsp;type="java.lang.String"/&gt;<BR>　　&lt;form-property&nbsp;name="secondname"&nbsp;type="java.lang.String"&gt;<BR>　　&lt;form-property&nbsp;name="age"&nbsp;type="java.Integer"&nbsp;initial="18"&gt;<BR>　　&lt;/form-beans&gt;<BR>　　<BR>　　3&lt;global-exception&gt;元素<BR>　　<BR>　　&lt;global-exception&gt;用于配置异常处理，&lt;global-exception&gt;元素可以包含零个或者多个&lt;exception&gt;元素。<BR>　　<BR>　　&lt;exception&gt;元素用来设置java异常和异常处理类org.apache.structs.action,Exception　Hander之间的映射。<BR>　　<BR>　　4&lt;gloable-forwards&gt;元素<BR>　　<BR>　　&lt;global-forwards&gt;元素用来声明全局的转发关系，&lt;global-forwards&gt;有零个或多个&lt;forward&gt;元素组成。&lt;forward&gt;元素用于把一个逻辑映射到特定的URL<BR>　　<BR>　　属性　　　　　　描　述<BR>　　<BR>　　className　　和&lt;forward&gt;元素对应的配置类，默认为org.apache.structs.action.ActionForWard<BR>　　<BR>　　name　　　　&nbsp;转发路径的逻辑名，此项时必须的<BR>　　<BR>　　path　　　　&nbsp;指定或者重定向的URI。此项时必须的，必须以”/”开头<BR>　　<BR>　　redirect　　&nbsp;此项是true，表示是执行重定向的操作，此项是false时，表示请求转发。<BR>　　<BR>　　&lt;global-forwards&gt;<BR>　　&lt;forward&nbsp;name="forward1"&nbsp;path="/Action1.do"/&gt;<BR>　　&lt;forward&nbsp;name="forward1"&nbsp;path="/Action2.do"/&gt;<BR>　　&lt;/global-forwards&gt;<BR>　　<BR>　　如果jsp1.jsp把请求转发给Action1,可以使用以下代码：<BR>　　<BR>　　&lt;html:link&nbsp;forward=”forward1”&gt;<BR>　　<BR>　　或者&lt;logic:forward&nbsp;name=”forward1”&gt;<BR>　　<BR>　　如果Action1的execute（）方法把请求转发给JSP2.jsp，可以使用一下代码：<BR>　　<BR>　　return(mapping.findForward(“forward2”))<BR>　　<BR>　　5&lt;action-mapping&gt;元素<BR>　　<BR>　　&lt;action-mapping&gt;元素包含零个或者多个&lt;action&gt;元素。&lt;action&gt;元素描述了从特定的请求路径到相应的Action类的映射。<BR>　　<BR>　　6&lt;controller&gt;元素<BR>　　<BR>　　&lt;controller&gt;元素用于配置ActionServlet。<BR>　　<BR>　　7&lt;&nbsp;message-resources&gt;元素<BR>　　<BR>　　&lt;message-resources&gt;元素用于配置Resource&nbsp;Bundle，Resource&nbsp;Budle用于存放本地化消息文件。<BR>　　<BR>　　Structs标签<BR>　　<BR>　　HTML标签<BR>　　<BR>　　标签名　　　　　　　　描述<BR>　　base　　　　　　　　&nbsp;包装HTML的base元素<BR>　　button　　　　　　　&nbsp;包装HTML的&nbsp;button类型的input元素<BR>　　cancel　　　　　　　&nbsp;包装HTML&nbsp;cancel&nbsp;按钮<BR>　　checkbox　　　　　　&nbsp;包装HTML&nbsp;checkbox&nbsp;类型的输入域<BR>　　errors　　　　　　　&nbsp;有条件地显示一些error消息，显示ActionErrors信息<BR>　　file　　　　　　　　&nbsp;包装HTML文件上传输入域<BR>　　form　　　　　　　　&nbsp;定义HTML&nbsp;form&nbsp;元素<BR>　　frame　　　　　　　　包装HTML&nbsp;frame&nbsp;元素<BR>　　hidden　　　　　　　&nbsp;包装HTML&nbsp;hidden&nbsp;输入域<BR>　　html　　　　　　　　&nbsp;包装&nbsp;HTML中的&nbsp;html&nbsp;元素<BR>　　image　　　　　　　　包装&nbsp;"image"类型的输入域<BR>　　img　　　　　　　　　包装HTML的&nbsp;img&nbsp;元素<BR>　　javascript　　　　　&nbsp;包装根据ValidatorPlugIn提供的校验规则所提供的javascript校验脚本<BR>　　link　　　　　　　　&nbsp;包装超链接<BR>　　messages　　　　　　&nbsp;有条件地显示一些提示信息，显示ActionMessages信息<BR>　　multibox　　　　　　&nbsp;包装多选输入框<BR>　　option　　　　　　　&nbsp;包装一个选择输入框<BR>　　options　　　　　　　包装一批选择输入框<BR>　　optionsCollection　　包装一批选择输入框集<BR>　　password　　　　　　&nbsp;包装密文输入框<BR>　　radio　　　　　　　　包装单选输入框<BR>　　reset　　　　　　　　包装“重置”功能的按钮<BR>　　rewrite　　　　　　　包装一个URL<BR>　　select　　　　　　　&nbsp;包装一个选择输入框<BR>　　submit　　　　　　　&nbsp;包装一个提交按钮<BR>　　text　　　　　　　　&nbsp;包装一个文本输入框<BR>　　textarea　　　　　　&nbsp;包装一个备注输入框<BR>　　<BR>　　ActionForm<BR>　　ActionForm&nbsp;的要求<BR>　　<BR>　　创建一个ActionForm&nbsp;并不困难，但是你的类必须符合一些要求：<BR>　　<BR>　　ActionForm&nbsp;必须扩展自org.apache.struts.ActionForm。基类ActionForm&nbsp;是不能实例化的。<BR>　　<BR>　　ActionForm&nbsp;必须为每个应该从请求中收集的HTML控件定义一个公共属性。<BR>　　<BR>　　(Struts&nbsp;1.0&nbsp;要求每个属性都要mutator&nbsp;和accessor&nbsp;。Struts&nbsp;1.1&nbsp;则没有如此严格)<BR>　　<BR>　　ActionForm还可能要符合一些可选的要求:<BR>　　<BR>　　如果你要求ActionForm&nbsp;在传递属性到Action之前校验它们，你就必须实现validate<BR>　　<BR>　　方法；<BR>　　<BR>　　如果想在组装前初始化属性，必须实现reset&nbsp;,&nbsp;它在ActionForm&nbsp;组装前被调用；<BR>　　<BR>　　动态ActionForm<BR>　　<BR>　　ActionForm&nbsp;作为类型转换器<BR>　　<BR>　　ActionForm的一个强制点是应该使用String&nbsp;和boolean属性。实际上，这意味着属性<BR>　　<BR>　　必须得从一种转换到另一种类型。大部分应用也需要一些属性，比如电话号码或者数量，以<BR>　　<BR>　　一种格式化的方式出现。核心Java&nbsp;包提供一些工具来做这种事情，但是要清楚地将他们集<BR>　　<BR>　　成到应用中仍然是一个挑战。<BR>　　<BR>　　Struts&nbsp;开发人员经常在ActionForm中包含helper方法，来进行类型转换。helper&nbsp;方法<BR>　　<BR>　　可以有很多种实现方式，这我们在5.6种叙述。<BR>　　<BR>　　5.2.6&nbsp;ActionForm&nbsp;作为防火墙<BR>　　<BR>　　当请求提交时，ActionServlet&nbsp;使用一个自动组装机制来从请求参数中设置请求的<BR>　　<BR>　　ActionForm属性。这让你可以通过控制哪个ActionForm&nbsp;属性被暴露来控制哪个请求参数<BR>　　<BR>　　是可接受的。这也意味着如果你的ActionForm&nbsp;的粗心设计你可能失去控制哪个参数可以接<BR>　　<BR>　　受的能力。ActionForm&nbsp;一定不能包含看起来像是一个JavaBean&nbsp;属性，但不能从HTTP&nbsp;请<BR>　　<BR>　　求设置的属性方法。<BR>　　<BR>　　5.3.4&nbsp;ActionForm&nbsp;可以嵌套其它bean<BR>　　<BR>　　因为Struts&nbsp;标签扩展和自动组装机制都支持点号语法来从ActionForm访问其它<BR>　　<BR>　　bean。这是一个方便的方式，可以通过ActionForm来组装存在的bean。在JSP&nbsp;页面,&nbsp;你可<BR>　　<BR>　　以象这样引用一个嵌套的bean：<BR>　　<BR>　　&lt;html:text<BR>　　propety="values.telephoneText"<BR>　　size="14"<BR>　　maxlength="14"/&gt;<BR>　　<BR>　　5.7.2&nbsp;分发（Dispatch&nbsp;）<BR>　　<BR>　　Struts&nbsp;开发人员通常使用同一个Action处理相关的操作。一个通常做法来选择操作是在HTML表单中使用隐藏属性。BaseForm&nbsp;的dispatch&nbsp;属性也可用作这个目的：<BR>　　public&nbsp;void&nbsp;setDispatch(String&nbsp;dispatch);<BR>　　public&nbsp;String&nbsp;getDispatch();<BR>　　<BR>　　Struts&nbsp;配置提供连个级别嵌套的ActionForward:<BR>　　<BR>　　Global&nbsp;（全局）&nbsp;ActionForward对整个应用中的所有Action&nbsp;对象均有效；<BR>　　<BR>　　Local&nbsp;（局部）&nbsp;ActionForward&nbsp;则在ActionMapping&nbsp;元素中定义。仅对那些在这个<BR>　　<BR>　　ActionMapping中调用的Action对象有效。<BR>　　<BR>　　从Action&nbsp;对象内部来看，forward&nbsp;通常像这样来选择：<BR>　　ActionForward&nbsp;forward&nbsp;=&nbsp;mapping.findForward("continue"); <BR><img src ="http://www.blogjava.net/yesjoy/aggbug/31830.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yesjoy/" target="_blank">★yesjoy★</a> 2006-02-21 17:33 <a href="http://www.blogjava.net/yesjoy/articles/31830.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>struts傻瓜式学习（实例入门）</title><link>http://www.blogjava.net/yesjoy/articles/31829.html</link><dc:creator>★yesjoy★</dc:creator><author>★yesjoy★</author><pubDate>Tue, 21 Feb 2006 09:27:00 GMT</pubDate><guid>http://www.blogjava.net/yesjoy/articles/31829.html</guid><wfw:comment>http://www.blogjava.net/yesjoy/comments/31829.html</wfw:comment><comments>http://www.blogjava.net/yesjoy/articles/31829.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/yesjoy/comments/commentRss/31829.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yesjoy/services/trackbacks/31829.html</trackback:ping><description><![CDATA[作者：林佩雯<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;或许有人觉得struts不容易学，似乎里面的一些概念让未接触过的人迷惑，MVC1、MVC2、模式……我写这篇文章是想让从来没有接触过struts的人，能有个简单的入门指引，当然，系统地学习struts是必要的，里面有很多让人心醉的东东，那是后话了。<BR>&nbsp;&nbsp;&nbsp;&nbsp;该案例包括首页，用户登陆、网站向导页面。就这么简单，没有深奥的struts概念，主要靠动手，然后用心体会~!@#$%^&amp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;WEB&nbsp;Server用tomcat4。到<A href="http://jakarta.apache.org/">http://jakarta.apache.org</A>下载struts1.1，把zip文件释放到c:\struts，拷贝C:\struts\webapps\struts-example.war到c:\tomcat4\webapps中，启动tomcat，war包被释放为struts-example文件夹，删除war包，把struts-example文件夹更名为test。<BR>一、把WEB-INF\web.xml改成：<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: #0000ff">&lt;?</SPAN><SPAN style="COLOR: #ff00ff">xml&nbsp;version="1.0"&nbsp;encoding="ISO-8859-1"</SPAN><SPAN style="COLOR: #0000ff">?&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;!</SPAN><SPAN style="COLOR: #ff00ff">DOCTYPE&nbsp;web-app&nbsp;PUBLIC&nbsp;"-//Sun&nbsp;Microsystems,&nbsp;Inc.//DTD&nbsp;Web&nbsp;Application&nbsp;2.2//EN"&nbsp;&nbsp;"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">web-app</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">&lt;!--</SPAN><SPAN style="COLOR: #008000">这是struts中的Controller（控制器），系统的指令中转由其，既ActionServlet&nbsp;类负责，它从struts-config.xml中读取配置信息，并在服务器后台自动启动一个线程。如果没有特别的要求（如添加语言编转功能），程序员可以不管这部分，照用就可以了。</SPAN><SPAN style="COLOR: #008000">--&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;<BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">servlet</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">servlet-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">action</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">servlet-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">servlet-class</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">org.apache.struts.action.ActionServlet</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">servlet-class</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">init-param</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">param-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">config</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">param-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">param-value</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">/WEB-INF/struts-config.xml</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">param-value</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">init-param</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">load-on-startup</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">load-on-startup</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">servlet</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">&lt;!--</SPAN><SPAN style="COLOR: #008000">该系统的servlet可以映射成cool为后缀的文件，而不是常见的.jspdo等，后缀名可以改成任何名称，当然名字要健康＃◎￥％！</SPAN><SPAN style="COLOR: #008000">--&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">servlet-mapping</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">servlet-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">action</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">servlet-name</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">url-pattern</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">*.cool</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>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">servlet-mapping</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">&lt;!--</SPAN><SPAN style="COLOR: #008000">该系统的默认首页是index.jsp，可以有多个，系统按次序找，类似IIS</SPAN><SPAN style="COLOR: #008000">--&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;<BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">welcome-file-list</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">welcome-file</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">index.jsp</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">welcome-file</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">welcome-file-list</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">web-app</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN></DIV>二、把test\WEB-INF\&nbsp;struts-config.xml改成：<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: #0000ff">&lt;?</SPAN><SPAN style="COLOR: #ff00ff">xml&nbsp;version="1.0"&nbsp;encoding="ISO-8859-1"&nbsp;</SPAN><SPAN style="COLOR: #0000ff">?&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;!</SPAN><SPAN style="COLOR: #ff00ff">DOCTYPE&nbsp;struts-config&nbsp;PUBLIC&nbsp;"-//Apache&nbsp;Software&nbsp;Foundation//DTD&nbsp;Struts&nbsp;Configuration&nbsp;1.1//EN"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">struts-config</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">&lt;!--</SPAN><SPAN style="COLOR: #008000">FormBean是struts的一个概念，本质是JavaBean，用来自动存储页面表单中各个域的值，并在适当的时候回填表单域，不需要象传统那样request.getParameter(“fieldName”);，常被action-mappings中的action&nbsp;使用</SPAN><SPAN style="COLOR: #008000">--&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">form-beans</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">&lt;!--</SPAN><SPAN style="COLOR: #008000">稍后我们会新增一个UserForm类，用来存储用户信息。</SPAN><SPAN style="COLOR: #008000">--&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">form-bean&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="userForm"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;type</SPAN><SPAN style="COLOR: #0000ff">="test.UserForm"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">form-beans</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">&lt;!--</SPAN><SPAN style="COLOR: #008000">这里存放整个系统都可以使用的全局转向中转(Forward)地址，类似于javascript中的window.location(‘index.jsp’);，也类似于电视控制器上的各种按钮，可以转频道、调色等等是基于Struts的Web应用的控制流程流转。一般情况下，一个Action处理完毕后，会转发到一个JSP页面进行显示。这也是JSP中的MVC的实现的要点。</SPAN><SPAN style="COLOR: #008000">--&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">global-forwards</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">&lt;!--</SPAN><SPAN style="COLOR: #008000">failed.cool将被当成servlet请求，到action-mappings中寻找对应的action处理。</SPAN><SPAN style="COLOR: #008000">--&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">forward&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="failed"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;path</SPAN><SPAN style="COLOR: #0000ff">="/failed.cool"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">forward&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="regist"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;path</SPAN><SPAN style="COLOR: #0000ff">="/regist.jsp"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">global-forwards</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">&lt;!--</SPAN><SPAN style="COLOR: #008000">还记得web.xml中后缀为cool的请求吗？它们是转到这里处理的。这里相当于struts的Model部分，Model部分是struts中比较灵活的地方。</SPAN><SPAN style="COLOR: #008000">--&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">action-mappings</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">&lt;!--</SPAN><SPAN style="COLOR: #008000">处理regist.cools的请求，使用的FormBean是userForm，既test.UserForm类，当处理过程发生错误时将返回index.jsp</SPAN><SPAN style="COLOR: #008000">--&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">action&nbsp;</SPAN><SPAN style="COLOR: #ff0000">path</SPAN><SPAN style="COLOR: #0000ff">="/regist"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;type</SPAN><SPAN style="COLOR: #0000ff">="test.RegistAction"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;name</SPAN><SPAN style="COLOR: #0000ff">="userForm"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;scope</SPAN><SPAN style="COLOR: #0000ff">="request"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;input</SPAN><SPAN style="COLOR: #0000ff">="/index.jsp"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">action&nbsp;</SPAN><SPAN style="COLOR: #ff0000">path</SPAN><SPAN style="COLOR: #0000ff">="/overview"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;forward</SPAN><SPAN style="COLOR: #0000ff">="/hello.jsp"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">action&nbsp;</SPAN><SPAN style="COLOR: #ff0000">path</SPAN><SPAN style="COLOR: #0000ff">="/failed"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;forward</SPAN><SPAN style="COLOR: #0000ff">="/wuwu.jsp"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">action-mappings</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">struts-config</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN></DIV>三、增加一个FormBean，类路径为test.UserForm，以下是这个类的内容：<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: #0000ff">package</SPAN><SPAN style="COLOR: #000000">&nbsp;test;&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000">&nbsp;org.apache.struts.action.ActionForm;&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;UserForm&nbsp;</SPAN><SPAN style="COLOR: #0000ff">extends</SPAN><SPAN style="COLOR: #000000">&nbsp;ActionForm&nbsp;<BR>{&nbsp;<BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;String&nbsp;name</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">yesjoy</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">用户名&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;String&nbsp;ps</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">1234</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">密码&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;UserForm(){}&nbsp;<BR>&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;s)&nbsp;{name</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">s;}&nbsp;<BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;String&nbsp;getName()&nbsp;{</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;name;}&nbsp;<BR>&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;setPs(String&nbsp;s)&nbsp;{ps</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">s;}&nbsp;<BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;String&nbsp;getPs()&nbsp;{</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;ps;}&nbsp;<BR>}&nbsp;<BR></SPAN></DIV>四、增加一个Action的子类，类路径为test.&nbsp;RegistAction，以下是这个类的内容：<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: #0000ff">package</SPAN><SPAN style="COLOR: #000000">&nbsp;test;&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000">&nbsp;java.lang.reflect.InvocationTargetException;&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000">&nbsp;java.util.Locale;&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000">&nbsp;javax.servlet.ServletException;&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000">&nbsp;javax.servlet.http.HttpServletRequest;&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000">&nbsp;javax.servlet.http.HttpSession;&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000">&nbsp;javax.servlet.http.HttpServletResponse;&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000">&nbsp;org.apache.struts.action.Action;&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000">&nbsp;org.apache.struts.action.ActionError;&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000">&nbsp;org.apache.struts.action.ActionErrors;&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000">&nbsp;org.apache.struts.action.ActionForm;&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000">&nbsp;org.apache.struts.action.ActionForward;&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000">&nbsp;org.apache.struts.action.ActionMapping;&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000">&nbsp;org.apache.struts.util.MessageResources;&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN style="COLOR: #000000">&nbsp;test.UserForm;&nbsp;<BR><BR></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">final</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;RegistAction&nbsp;</SPAN><SPAN style="COLOR: #0000ff">extends</SPAN><SPAN style="COLOR: #000000">&nbsp;Action&nbsp;<BR>{&nbsp;<BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;ActionForward&nbsp;execute(ActionMapping&nbsp;mapping,ActionForm&nbsp;form,&nbsp;<BR>&nbsp;&nbsp;&nbsp;HttpServletRequest&nbsp;request,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;HttpServletResponse&nbsp;response)&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throws</SPAN><SPAN style="COLOR: #000000">&nbsp;Exception&nbsp;<BR>&nbsp;&nbsp;{&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;Locale&nbsp;locale&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;getLocale(request);&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;MessageResources&nbsp;messages&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;getResources(request);&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;HttpSession&nbsp;session&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;request.getSession();&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;UserForm&nbsp;userform&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(UserForm)&nbsp;form;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">此处可以调用其他类来执行数据库写入或其他逻辑判断&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;如果UserForm传来的参数name的值为默认的lpw，将forward到failed，&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;该名称将到struts-config.xml的&lt;global-forwards&gt;中寻找映射的url地址&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;（可以是绝对路径，也可以是相对路径），对于本例，是转到failed.cool，&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;还记得吗？后缀为cool的请求全部到action-mappings中寻找&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;对应的action处理，最终目录是wuwu.jsp*/&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">lpw</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">.equals(userform.getName())&nbsp;)&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;(mapping.findForward(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">failed</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;(mapping.findForward(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">regist</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));&nbsp;<BR>&nbsp;&nbsp;}&nbsp;<BR>}&nbsp;<BR></SPAN></DIV>五、以下所有新增或修改的页面相当于struts的View部分，把首页index.jsp改成：<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; BACKGROUND-COLOR: #ffff00">&lt;%</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">@&nbsp;page&nbsp;contentType</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">text/html;charset=GBK</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;language</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">java</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">%&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">&lt;%</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">@&nbsp;page&nbsp;import&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">test.*</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">%&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">a&nbsp;</SPAN><SPAN style="COLOR: #ff0000">href</SPAN><SPAN style="COLOR: #0000ff">="overview.cool"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">站点导航</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">a</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;</SPAN><SPAN style="COLOR: #800000">br</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">form&nbsp;</SPAN><SPAN style="COLOR: #ff0000">action</SPAN><SPAN style="COLOR: #0000ff">="regist.cool"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;method</SPAN><SPAN style="COLOR: #0000ff">="post"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008000">&lt;!--</SPAN><SPAN style="COLOR: #008000">表单中的域的名称要和UserForm中的参数一样，就可以实现数据自动获取功能，不需要用request.getParameter("param");</SPAN><SPAN style="COLOR: #008000">--&gt;</SPAN><SPAN style="COLOR: #000000"><BR>用户:</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">input&nbsp;</SPAN><SPAN style="COLOR: #ff0000">type</SPAN><SPAN style="COLOR: #0000ff">="text"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;name</SPAN><SPAN style="COLOR: #0000ff">="name"</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;</SPAN><SPAN style="COLOR: #800000">br</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>密码:</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">input&nbsp;</SPAN><SPAN style="COLOR: #ff0000">type</SPAN><SPAN style="COLOR: #0000ff">="password"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;name</SPAN><SPAN style="COLOR: #0000ff">="ps"</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;</SPAN><SPAN style="COLOR: #800000">br</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">input&nbsp;</SPAN><SPAN style="COLOR: #ff0000">type</SPAN><SPAN style="COLOR: #0000ff">=submit&nbsp;</SPAN><SPAN style="COLOR: #ff0000">value</SPAN><SPAN style="COLOR: #0000ff">="新增用户"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">form</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN></DIV>六、增加hello.jsp，用于站点导航：<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: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">h1</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">site&nbsp;map</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">h1</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">The&nbsp;following&nbsp;is&nbsp;content&nbsp;filling&nbsp;by&nbsp;reader</SPAN></DIV>七、增加wuwu.jsp，当没有新用户登陆时，将转到这个页面：<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; BACKGROUND-COLOR: #ffff00">&lt;%</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">@&nbsp;page&nbsp;contentType</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">text/html;charset=GBK</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;language</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">java</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">%&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">jsp:useBean&nbsp;</SPAN><SPAN style="COLOR: #ff0000">id</SPAN><SPAN style="COLOR: #0000ff">="beanlpw"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;class</SPAN><SPAN style="COLOR: #0000ff">="test.UserForm"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;scope</SPAN><SPAN style="COLOR: #0000ff">="session"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR>现有用户：</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">&lt;%</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">beanlpw.getName()</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">%&gt;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">br</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>密码：</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">&lt;%</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">beanlpw.getPs()</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">%&gt;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">br</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>没有得到新的用户！55555～～～～～</SPAN></DIV>八、增加regist.jsp，当有新用户登陆时，将转到这个页面：<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; BACKGROUND-COLOR: #ffff00">&lt;%</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">@&nbsp;page&nbsp;contentType</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">text/html;charset=GBK</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;language</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">java</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">&nbsp;</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">%&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">jsp:useBean&nbsp;</SPAN><SPAN style="COLOR: #ff0000">id</SPAN><SPAN style="COLOR: #0000ff">="beanlpw"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;class</SPAN><SPAN style="COLOR: #0000ff">="test.UserForm"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;scope</SPAN><SPAN style="COLOR: #0000ff">="session"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR>新用户帐号：</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">&lt;%</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">beanlpw.getName()</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">%&gt;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">br</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>密码：</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">&lt;%</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">beanlpw.getPs()</SPAN><SPAN style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">%&gt;</SPAN></DIV>九、启动tomcat4，浏览器中键入http://localhost:8080/test/index.jsp，操作一下，就可以看到结果，并初步理解struts的M、V、C各部分的协同工作原理，当然这是作者的良好意愿，如果读者看得一头雾水，欢迎指出错误在哪里&nbsp;&nbsp;：） <img src ="http://www.blogjava.net/yesjoy/aggbug/31829.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yesjoy/" target="_blank">★yesjoy★</a> 2006-02-21 17:27 <a href="http://www.blogjava.net/yesjoy/articles/31829.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用Struts建立MVC应用的介绍</title><link>http://www.blogjava.net/yesjoy/articles/30948.html</link><dc:creator>★yesjoy★</dc:creator><author>★yesjoy★</author><pubDate>Thu, 16 Feb 2006 03:23:00 GMT</pubDate><guid>http://www.blogjava.net/yesjoy/articles/30948.html</guid><wfw:comment>http://www.blogjava.net/yesjoy/comments/30948.html</wfw:comment><comments>http://www.blogjava.net/yesjoy/articles/30948.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yesjoy/comments/commentRss/30948.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yesjoy/services/trackbacks/30948.html</trackback:ping><description><![CDATA[<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR vAlign=top>
<TD width="100%">
<H1>用Struts建立MVC应用的介绍</H1><IMG class=display-img height=6 alt="" src="http://www.ibm.com/i/c.gif" width=1></TD>
<TD class=no-print width=192></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR vAlign=top>
<TD width=10><IMG height=1 alt="" src="http://www.ibm.com/i/c.gif" width=10></TD>
<TD width="100%">
<TABLE class=no-print cellSpacing=0 cellPadding=0 width=160 align=right border=0>
<TBODY>
<TR>
<TD width=10><IMG height=1 alt="" src="http://www.ibm.com/i/c.gif" width=10></TD>
<TD>
<TABLE cellSpacing=0 cellPadding=0 width=150 border=0>
<TBODY>
<TR>
<TD class=v14-header-1-small>文档选项</TD></TR></TBODY></TABLE>
<TABLE class=v14-gray-table-border cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD class=no-padding width=150>
<TABLE cellSpacing=0 cellPadding=0 width=143 border=0><IMG height=1 alt="" src="http://www.ibm.com/i/c.gif" width=8> 
<FORM name=email action=https://www-130.ibm.com/developerworks/secure/email-it.jsp><INPUT type=hidden value=本文讲述了如何用Struts建立MVC应用。 name=body><INPUT type=hidden value=用Struts建立MVC应用的介绍 name=subject><INPUT type=hidden value=cn name=lang>
<SCRIPT language=JavaScript type=text/javascript>
<!--
document.write('<tr valign="top"><td width="8"><img src="//www.ibm.com/i/c.gif" width="8" height="1" alt=""/></td><td width="16"><img src="//www.ibm.com/i/v14/icons/em.gif" height="16" width="16" vspace="3" alt="将此页作为电子邮件发送" /></td><td width="122"><p><a class="smallplainlink" href="javascript:document.email.submit();"><b>将此页作为电子邮件发送</b></a></p></td></tr>');
//-->
</SCRIPT>
 
<TBODY>
<TR vAlign=top>
<TD width=8><IMG height=1 alt="" src="http://www.ibm.com/i/c.gif" width=8></TD>
<TD width=16><IMG height=16 alt=将此页作为电子邮件发送 src="http://www.ibm.com/i/v14/icons/em.gif" width=16 vspace=3></TD>
<TD width=122>
<P><A class=smallplainlink href="javascript:document.email.submit();"><B><FONT color=#5c81a7>将此页作为电子邮件发送</FONT></B></A></P></TD></TR><NOSCRIPT><tr valign="top"><td width="8"><img alt="" height="1" width="8" src="//www.ibm.com/i/c.gif"/></td><td width="16"><img alt="" width="16" height="16" src="//www.ibm.com/i/c.gif"/></td><td class="small" width="122"><p><span class="ast">未显示需要 JavaScript 的文档选项</span></p></td></tr></NOSCRIPT></FORM></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE cellSpacing=0 cellPadding=0 width=150 border=0>
<TBODY>
<TR>
<TD class=v14-header-1-small>对此页的评价</TD></TR></TBODY></TABLE>
<TABLE class=v14-gray-table-border cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD class=no-padding width=150>
<TABLE cellSpacing=0 cellPadding=0 width=143 border=0>
<TBODY>
<TR vAlign=top>
<TD width=8><IMG height=1 alt="" src="http://www.ibm.com/i/c.gif" width=8></TD>
<TD><IMG height=16 alt="" src="http://www.ibm.com/i/v14/icons/d_bold.gif" width=16 vspace=3 border=0></TD>
<TD width=125>
<P><A class=smallplainlink href="http://www-128.ibm.com/developerworks/cn/java/l-struts-mvc/index.html#rate"><B><FONT color=#996699>帮助我们改进这些内容</FONT></B></A></P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR></TD></TR></TBODY></TABLE>
<P>级别: 初级</P>
<P><A href="http://www-128.ibm.com/developerworks/cn/java/l-struts-mvc/index.html#author"><FONT color=#996699>赵晨希</FONT></A>, <BR></P>
<P>2002 年 12 月 11 日</P>
<BLOCKQUOTE>本文讲述了如何用Struts建立MVC应用。</BLOCKQUOTE>
<P><A name=1><SPAN class=atitle><FONT face=Arial size=4>Model 1 和Model 2简介</FONT></SPAN></A></P>
<P><FONT face=Arial size=4></FONT>
<P>我们在开发Web应用时经常提到的一个概念是Model 1/Model 2，那么到底它是什么意思呢？其实它是对采用JSP技术构成Web应用的不同模型的描述。下面对这个概念做一个简单的介绍。</P>
<P><A name=N10043><SPAN class=smalltitle><STRONG><FONT face=Arial>Model 1</FONT></STRONG></SPAN></A></P>
<P><STRONG><FONT face=Arial></FONT></STRONG>
<P>在使用JAVA技术建立Web应用的实例中，由于JSP技术的发展，很快这种便于掌握和可实现快速开发的技术就成了创建Web应用的主要技术。JSP页面中可以非常容易地结合业务逻辑(jsp:useBean)、服务端处理过程（jsp:scriplet）和HTML(&lt;html&gt;)，在JSP页面中同时实现显示，业务逻辑和流程控制，从而可以快速地完成应用开发。现在很多的Web应用就是由一组JSP页面构成的。这种以JSP为中心的开发模型我们可以称之为Model 1。</P>
<P>当然这种开发模式在进行快速和小规模的应用开发时，是有非常大的优势，但是从工程化的角度考虑，它也有一些不足之处：</P>
<OL>
<LI>应用的实现一般是基于过程的,一组JSP页面实现一个业务流程，如果要进行改动，必须在多个地方进行修改。这样非常不利于应用扩展和更新。 
<LI>由于应用不是建立在模块上的, 业务逻辑和表示逻辑混合在JSP页面中没有进行抽象和分离。所以非常不利于应用系统业务的重用和改动。 </LI></OL>
<P>考虑到这些问题在开发大型的Web应用时必须采用不同的设计模式--这就是Model2</P>
<P><A name=N1005D><SPAN class=smalltitle><STRONG><FONT face=Arial>Model 2</FONT></STRONG></SPAN></A></P>
<P><STRONG><FONT face=Arial></FONT></STRONG>
<P>Model 2 表示的是基于MVC模式的框架。MVC是Model－View－Controller的简写。"Model" 代表的是应用的业务逻辑（通过JavaBean，EJB组件实现）， "View" 是应用的表示面（由JSP页面产生），"Controller" 是提供应用的处理过程控制（一般是一个Servlet），通过这种设计模型把应用逻辑，处理过程和显示逻辑分成不同的组件实现。这些组件可以进行交互和重用。从而弥补了Model 1的不足。</P>
<P>Model 2具有组件化的优点从而更易于实现对大规模系统的开发和管理，但是开发MVC系统比简单的JSP开发要复杂许多，它需要更多的时间学习和掌握。同时新东西的引入会带来新的问题（这让我想起来关于"自动计算"的一篇文章，中间提到为了降低系统的复杂度，却导致更高的复杂度）。</P>
<OL>
<LI>必须基于MVC组件的方式重新思考和设计应用结构。原来通过建立一个简单的JSP页面就能实现的应用现在变成了多个步骤的设计和实现过程。 
<LI>所有的页面和组件必须在MVC框架中实现，所以必须进行附加地开发工作。 </LI></OL>
<P>MVC本身就是一个非常复杂的系统，所以采用MVC实现Web应用时，最好选一个现成的MVC框架，在此之下进行开发，从而取得事半功倍的效果。现在有很多可供使用的MVC框架，由于Struts有完整的文档并且相对来讲比较简单，所以用它开发MVC系统还是比较方便地。</P><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD><IMG height=1 alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%"></TD></TR></TBODY></TABLE>
<TABLE class=no-print cellSpacing=0 cellPadding=0 align=right>
<TBODY>
<TR align=right>
<TD>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD vAlign=center><IMG height=16 alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width=16 border=0><BR></TD>
<TD vAlign=top align=right><A class=fbox href="http://www-128.ibm.com/developerworks/cn/java/l-struts-mvc/index.html#main"><B><FONT color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=2><SPAN class=atitle><FONT face=Arial size=4>Struts的结构和处理流程简介</FONT></SPAN></A></P>
<P><FONT face=Arial size=4></FONT>
<P>Struts是Apache组织的一个项目，像其他的Apache组织的项目一样，它也是开放源码项目。Struts是一个比较好的MVC框架提供了对开发MVC系统的底层支持，它采用的主要技术是Servlet，JSP和custom tag library。获取它的使用版本和具体信息可以查阅 <A href="http://jakarta.apache.org/"><FONT color=#5c81a7>http://jakarta.apache.org</FONT></A>网站。 </P>
<P>Struts框架的基本构成由下图所示：</P><BR><A name=N1008B><B>图 1 struts uml图</B></A><BR><IMG height=483 alt="图 1 struts uml图" src="http://www-128.ibm.com/developerworks/cn/java/l-struts-mvc/image001.jpg" width=760> <BR>
<P>作为一个MVC的框架，Struts对Model、View和Controller都提供了对应的实现组件，对应上面的UML图，分别进行介绍，并且看看它们是如何结合在一起的。</P>
<OL>
<LI>Controller：控制器的作用是从客户端接受请求，并且选择执行相应的业务逻辑，然后把响应结果送回到客户端。在Struts中Controller功能由图中ActionServlet和ActionMapping对象构成：核心是一个Servlet类型的对象ActionServlet，它用来接受客户端的请求。ActionServlet包括一组基于配置的ActionMapping对象，每个ActionMapping对象实现了一个请求到一个具体的Model部分中Action处理器对象之间的映射。 
<LI>Model： MVC系统中的Model部分从概念上可以分为两类--系统的内部状态，和改变系统状态的动作。Struts为Model部分提供了Action和ActionForm对象：所有的Action处理器对象都是开发者从Struts的Action类派生的子类。Action处理器对象封装了具体的处理逻辑，调用业务逻辑模块，并且把响应提交到合适的View组件以产生响应。Struts提供的ActionForm组件对象，它可以通过定义属性描述客户端表单数据。开发者可以从它派生子类对象，利用它和Struts提供的自定义标记库结合可以实现对客户端的表单数据的良好封装和支持，Action处理器对象可以直接对它进行读写，而不再需要和request、response对象进行数据交互。通过ActionForm组件对象实现了对View和Model之间交互的支持。Struts通常建议使用一组JavaBean表示系统的内部状态，根据系统的复杂度也可以使用像Entity EJB 和 Session EJB等组件来实现系统状态。Struts建议在实现时把"做什么"（Action）和"如何做"（业务逻辑）分离。这样可以实现业务逻辑的重用。 
<LI>View：Struts应用中的View部分是通过JSP技术实现的。Struts提供了自定义的标记库可以使用，通过这些自定义标记可以非常好地和系统的Model部分交互，通过使用这些自定义标记创建的JSP表单，可以实现和Model部分中的ActionForm的映射，完成对用户数据的封装，同时这些自定义标记还提供了像模板定制等多种显示功能。 </LI></OL>
<P>Struts框架的处理流程清楚的体现了MVC系统的特点，简单的Struts组件结构如图2所示。Struts Controller ActionServlet处理客户请求，利用配置的ActionMapping对象把请求映射到Action处理器对象进行处理。Action处理对象访问ActionForm中的数据，处理和响应客户请求，它还调用后台的Bean组件，这些组件封装了具体的业务逻辑。Action处理器对象根据处理结果通知Controller，Controller进行下一步的处理。</P><BR><A name=N100AC><B>图2 Struts框架的组件结构图</B></A><BR><IMG height=322 alt="图2 Struts框架的组件结构图" src="http://www-128.ibm.com/developerworks/cn/java/l-struts-mvc/image003.jpg" width=322> <BR><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD><IMG height=1 alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%"></TD></TR></TBODY></TABLE>
<TABLE class=no-print cellSpacing=0 cellPadding=0 align=right>
<TBODY>
<TR align=right>
<TD>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD vAlign=center><IMG height=16 alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width=16 border=0><BR></TD>
<TD vAlign=top align=right><A class=fbox href="http://www-128.ibm.com/developerworks/cn/java/l-struts-mvc/index.html#main"><B><FONT color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=3><SPAN class=atitle><FONT face=Arial size=4>利用Struts框架开发MVC系统要做的工作</FONT></SPAN></A></P>
<P><FONT face=Arial size=4></FONT>
<P>由于Struts已经为我们提供了一个非常好的MVC框架，我们利用Struts开发MVC系统时可以大大加快开发的速度。在开发时可以采用的一个开发流程如下（引自资料3）：</P>
<OL>
<LI>收集和定义应用需求。 
<LI>基于数据采集和显示的原则定义和开发"屏幕显示"需求 。 
<LI>为每一个"屏幕显示"定义访问路径。 
<LI>定义ActionMappings建立到应用业务逻辑之间的联系。 
<LI>开发满足"屏幕显示"需求的所有支持对象。 
<LI>基于每一个"屏幕显示"需求提供的数据属性来创建对应的ActionForm对象 
<LI>开发被ActionMapping调用的Action对象。 
<LI>开发应用业务逻辑对象 (Bean，EJB，等等)。 
<LI>对应ActionMapping设计的流程创建JSP页面。 
<LI>建立合适的配置文件struts-config.xml ， web.xml。 
<LI>开发/测试/部署 </LI></OL>
<P>具体在使用Struts框架时，对应各个部分的开发工作主要包括：</P>
<OL>
<LI>Model部分：采用JavaBean和EJB组件，设计和实现系统的业务逻辑。根据不同的请求从Action派生具体Action处理对象。完成"做什么"的任务来调用由Bean构成的业务组件。创建由ActionForm 的派生类实现对客户端表单数据的封装。 
<LI>Controller部分：Struts为我们提供了核心控制部分的实现。我们只需要配置ActionMapping对象 
<LI>View部分：为了使用Model中的ActionForm 对象，我们必须用Struts提供的自定义标记创建HTML 表单。利用Struts提供的自定义标记库编写用户界面把应用逻辑和显示逻辑分离。Struts框架通过这些自定义标记建立了View和Model之间的联系。Struts的自定义标记还提供了很多定制页面的功能。 
<LI>同时需要编辑两个配置文件：web.xml和struts-config.xml。通过它们配置Struts系统中的各个模块之间的交互。下面对这两个配置文件做一些介绍： 
<P>web.xml文件的配置：</P>
<P>web应用中的web.xml是第一个要配置的地方，它描述了系统的Controller对象。在web.xml中增加如下标记</P>
<TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">&lt;servlet&gt;
	&lt;servlet-name&gt;action&lt;/servlet-name&gt;
&lt;servlet-class&gt;org.apache.struts.action.ActionServlet&lt;/servlet-class&gt;
	&lt;init-param&gt;
		&lt;param-name&gt;application&lt;/param-name&gt;
	・・・・・・
&lt;/servlet&gt;
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>说明：这个servlet对象就是Struts提供的Controller，还可以为它指定初始化参数，比如对系统应用属性的支持。</P>
<TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">&lt;servlet-mapping&gt;
	&lt;servlet-name&gt;action&lt;/servlet-name&gt;
	&lt;url-pattern&gt;*.do&lt;/url-pattern&gt;
&lt;/servelt-mapping&gt;
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>说明：实现客户请求的url信息和服务器端具体处理的映射关系。</P>
<TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">&lt;taglib&gt;
	&lt;taglib-url&gt;/WEB-INF/struts-bean.tld&lt;/taglib-url&gt;
	&lt;taglib-location&gt;/WEB-INF/struts-bean.tld&lt;/taglib-location&gt;
&lt;/taglib&gt;
・・・・・・・
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>说明：添加对Struts提供的应用所使用的自定义标记库的引用。</P>
<P>struts-config.xml文件的配置：</P>
<P>struts-config.xml是用于建立Controller和Model之间的关系的。它描述了Controller所使用的把请求对应到具体处理的法则，同时它还描述了客户提供的数据与ActionForm组件的对应映射关系。</P>
<P>在struts-config.xml中增加如下标记</P>
<TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">&lt;form-beans&gt;
	&lt;form-bean name="loginForm" type="loginForm" /&gt;
&lt;/form-beans&gt;
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>说明：&lt;form-bean&gt;标记描述一个具体的ActionForm子类对象，通过它和JSP页面中的自定标记的结合使用可以实现ActionForm和View之间的数据映射。</P>
<TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">&lt;action-mappings&gt;
&lt;action
path="/login"
type="loginAction"
name="loginForm"
input="/login.jsp" ・・・ /&gt;
&lt;/action-mappings&gt;
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>说明：&lt;action-mappings&gt;标记描述了请求和处理的一对一映射关系。input和path属性唯一的标记了客户端的一个请求，name属性描述封装客户端的数据的ActionForm子类对象。Type属性描述处理这个请求的Action子类对象。</P>
<P>通过对两个配置文件的配置，把Struts框架中MVC的各个部分联系起来，实现一个真正的MVC系统。</P></LI></OL><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD><IMG height=1 alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%"></TD></TR></TBODY></TABLE>
<TABLE class=no-print cellSpacing=0 cellPadding=0 align=right>
<TBODY>
<TR align=right>
<TD>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD vAlign=center><IMG height=16 alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width=16 border=0><BR></TD>
<TD vAlign=top align=right><A class=fbox href="http://www-128.ibm.com/developerworks/cn/java/l-struts-mvc/index.html#main"><B><FONT color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=4><SPAN class=atitle><FONT face=Arial size=4>可供参考的例子</FONT></SPAN></A></P>
<P><FONT face=Arial size=4></FONT>
<P>编写一个好的例子演示是比较占篇幅的，可以从 <A href="http://jakarta.apache.org/"><FONT color=#5c81a7>http://jakarta.apache.org/</FONT></A>下载Struts最新的发表包，在这个包中有详细的用户帮助和API文档，还有非常好的演示程序可供参考。具体的安装步骤可以参考附带的文档。参考这些例子可以很快地理解如何利用struts框架开发MVC系统。 </P><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD><IMG height=1 alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%"></TD></TR></TBODY></TABLE>
<TABLE class=no-print cellSpacing=0 cellPadding=0 align=right>
<TBODY>
<TR align=right>
<TD>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD vAlign=center><IMG height=16 alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width=16 border=0><BR></TD>
<TD vAlign=top align=right><A class=fbox href="http://www-128.ibm.com/developerworks/cn/java/l-struts-mvc/index.html#main"><B><FONT color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=resources><SPAN class=atitle><FONT face=Arial size=4>参考资料 </FONT></SPAN></A></P>
<OL>
<LI>The Struts User's Guide <A href="http://jakarta.apache.org/"><FONT color=#5c81a7>http://Jakarta.apache.org</FONT></A> 
<LI>"Struts Tutorial" 作者：Stephan Wiesner 主页 <A href="http://www.stephanwiesner.de/"><FONT color=#5c81a7>www.stephanwiesner.de</FONT></A> 
<LI>Struts系列文章 <A href="http://www.onjava.com/onjava/open_source/"><FONT color=#5c81a7>http://www.onjava.com/onjava/open_source/</FONT></A> 
<LI>《设计模式》Gamma 等四人 </LI></OL><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD><IMG height=1 alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%"></TD></TR></TBODY></TABLE>
<TABLE class=no-print cellSpacing=0 cellPadding=0 align=right>
<TBODY>
<TR align=right>
<TD>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD vAlign=center><IMG height=16 alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width=16 border=0><BR></TD>
<TD vAlign=top align=right><A class=fbox href="http://www-128.ibm.com/developerworks/cn/java/l-struts-mvc/index.html#main"><B><FONT color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=author><SPAN class=atitle><FONT face=Arial size=4>关于作者</FONT></SPAN></A></P>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD colSpan=2><FONT face=Arial size=4><IMG height=5 alt="" src="http://www.ibm.com/i/c.gif" width="100%"></FONT></TD></TR>
<TR vAlign=top align=left>
<TD>
<P><FONT face=Arial size=4></FONT></P></TD>
<TD>
<P>赵晨希，一直集中在服务器端的程序开发上，喜欢用C++和Java编程，对新技术有极大的兴趣，目前个人兴趣在J2EE上和Open Source的项目上。希望和更多的爱好者交流。 Email： <A href="mailto:zhaochenxi@vip.sina.com"><FONT color=#5c81a7>zhaochenxi@vip.sina.com</FONT></A> </P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><img src ="http://www.blogjava.net/yesjoy/aggbug/30948.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yesjoy/" target="_blank">★yesjoy★</a> 2006-02-16 11:23 <a href="http://www.blogjava.net/yesjoy/articles/30948.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>