﻿<?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-闵毓-随笔分类-Struts in action</title><link>http://www.blogjava.net/shmily432685/category/4002.html</link><description /><language>zh-cn</language><lastBuildDate>Mon, 08 Oct 2007 04:35:52 GMT</lastBuildDate><pubDate>Mon, 08 Oct 2007 04:35:52 GMT</pubDate><ttl>60</ttl><item><title>myeclipse中weblogic服务简介</title><link>http://www.blogjava.net/shmily432685/archive/2005/11/26/21511.html</link><dc:creator>闵毓</dc:creator><author>闵毓</author><pubDate>Sat, 26 Nov 2005 08:11:00 GMT</pubDate><guid>http://www.blogjava.net/shmily432685/archive/2005/11/26/21511.html</guid><wfw:comment>http://www.blogjava.net/shmily432685/comments/21511.html</wfw:comment><comments>http://www.blogjava.net/shmily432685/archive/2005/11/26/21511.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.blogjava.net/shmily432685/comments/commentRss/21511.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/shmily432685/services/trackbacks/21511.html</trackback:ping><description><![CDATA[<H2 class=diaryTitle>myeclipse配置weblogic&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </H2>
<P>
<P>
<P>weblogic安装参见</P>
<P><A href="http://zhangstar.blogbus.com/logs/2004/09/413796.html">http://zhangstar.blogbus.com/logs/2004/09/413796.html</A></P>
<P>
<P>MyEclipse默认的应用服务器为JBoss3，这里我们使用WebLogic8.1。启动Eclipse，选择“窗口\首选项”菜单，打开首选项对话框。展开MyEclipse下的Application Servers结点，点击JBoss 3，选中右面的Disable单选按钮，停用JBoss 3。然后点击WebLogic 8，选中右边的Enable单选按钮，启用WebLogic服务器。同时下面的配置如下： <BR>(1)BEA home directory：C:\BEA。假定WebLogic安装在D:\BEA文件夹中。 <BR>(2)WebLogic installation directory：C:\BEA\weblogic81。 <BR>(3)Admin username：用户名。 <BR>(4)Admin password：密码。 <BR>(5)Execution domain root：安装后，启动服务的路径。 <BR>(6)Execution domain name：mydomain。 <BR>(7)Execution server name：myserver。 <BR>(8)Hostname:PortNumber：localhost:7001。 <BR>(9)Security policy file：D:\BEA\weblogic81\server\lib\weblogic.policy。 <BR>(10)JAAS login configuration file：省略。 <BR>以上配置根据安装情况不同而不同。<BR>如图：<BR><IMG height=529 alt=myeclipse_weblogic.JPG src="http://www.blogjava.net/images/blogjava_net/shmily432685/subject/myeclipse_weblogic.JPG" width=759 border=0><BR>接着展开WebLogic 8结点，点击JDK，在右边的WLS JDK name处选择WebLogic 8的默认JDK。这里组合框中缺省为j2re1.4.2_03，即之前单独安装的jre。单击Add按钮，弹出WebLogic &gt; Add JVM对话框，在JRE名称处随便输入一个名字，如jre1.4.1_02。然后在JRE主目录处选择WebLogic安装文件夹中的JDK文件夹，如D:\BEA\jdk141_02，程序会自动填充Javadoc URL文本框和JRE系统库列表框。单击确定按钮关闭对话框。这时候就可以在WLS JDK name组合框中选择jre1.4.1_02了。之后还要在下面的Optional Java VM arguments，如-ms64m -mx64m -Djava.library.path="D:/BEA/weblogic81/server/bin" -Dweblogic.management.discover=false -Dweblogic.ProductionModeEnabled=false <BR>最后点击Paths，在右边的Prepend to classpath列表框中，通过Add JAR/ZIP按钮，加入D:\BEA\weblogic81\server\lib\weblogic.jar、D:\BEA\weblogic81\server\lib\webservices.jar。如果用到数据库，还需把数据库的驱动类库加进来，这里我们用WebLogic自带的SQL Server数据库驱动库D:\BEA\weblogic81\server\lib\mssqlserver4v65.jar。 <BR>至此，MyEclipse中WebLogic8的配置工作就算完成了。下面可以看看在Eclipse中能否启动WebLogic了？自从安装了MyEclipse之后，Eclipse工具栏中就会有一个Run/Stop Servers下拉按钮。点击该按钮的下拉部分，选择“WebLogic 8\Start”菜单，即开始启动WebLogic了。通过查看下面的控制台消息，就可以知道启动是否成功，或有什么异常发生。停止WebLogic可选择“WebLogic\Stop”菜单</P><img src ="http://www.blogjava.net/shmily432685/aggbug/21511.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/shmily432685/" target="_blank">闵毓</a> 2005-11-26 16:11 <a href="http://www.blogjava.net/shmily432685/archive/2005/11/26/21511.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>web.xml规则经过整理总结如下：</title><link>http://www.blogjava.net/shmily432685/archive/2005/11/11/19258.html</link><dc:creator>闵毓</dc:creator><author>闵毓</author><pubDate>Fri, 11 Nov 2005 02:29:00 GMT</pubDate><guid>http://www.blogjava.net/shmily432685/archive/2005/11/11/19258.html</guid><wfw:comment>http://www.blogjava.net/shmily432685/comments/19258.html</wfw:comment><comments>http://www.blogjava.net/shmily432685/archive/2005/11/11/19258.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/shmily432685/comments/commentRss/19258.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/shmily432685/services/trackbacks/19258.html</trackback:ping><description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">1、部署描述符文件就像所有</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">XML</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">文件一样，必须以一个</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">XML</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">头开始。这个头声明可以使用的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">XML</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">版本并给出文件的字符编码。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>2、DOCYTPE</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">声明必须立即出现在此头之后。这个声明告诉服务器适用的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">servlet</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">规范的版本（如</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">2.2</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">或</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">2.3</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">）并指定管理此文件其余部分内容的语法的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">DTD(Document Type Definition</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">，文档类型定义</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">)</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR></SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">所有部署描述符文件的顶层（根）元素为</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">web-app</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">。请注意，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">XML</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素不像</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">HTML</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">，他们是大小写敏感的。因此，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">web-App</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">和</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">WEB-APP</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">都是不合法的，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">web-app</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">必须用小写。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><?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"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"></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: #008080">1</SPAN>&nbsp;<SPAN style="COLOR: #000000">&lt;?</SPAN><SPAN style="COLOR: #000000">xml&nbsp;version</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">1.0</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;encoding</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">UTF-8</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">?&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">2</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">3</SPAN>&nbsp;<SPAN style="COLOR: #000000"></SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">web</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">app&nbsp;xmlns</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">http://java.sun.com/xml/ns/j2ee</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;xmlns:xsi</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">http://www.w3.org/2001/XMLSchema-instance</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;version</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">2.4</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;xsi:schemaLocation</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">http://java.sun.com/xml/ns/j2ee&nbsp;&nbsp;&nbsp;http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">4</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">5</SPAN>&nbsp;<SPAN style="COLOR: #000000"></SPAN><SPAN style="COLOR: #000000">&lt;/</SPAN><SPAN style="COLOR: #000000">web</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">app</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">6</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">7</SPAN>&nbsp;<SPAN style="COLOR: #000000"></SPAN></DIV>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">2、 </SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">部署描述符文件内的元素次序</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 22pt; mso-char-indent-count: 2.0"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">XML </SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素不仅是大小写敏感的，而且它们还对出现在其他元素中的次序敏感。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 22pt; mso-char-indent-count: 2.0"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">XML</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">头必须是文件中的第一项，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">DOCTYPE</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">声明必须是第二项，而</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">web- app</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素必须是第三项。在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">web-app</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素内，元素的次序也很重要。服务器不一定强制要求这种次序，但它们允许（实际上有些服务器就是这样做的）完全拒绝执行含有次序不正确的元素的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">Web</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">应用。这表示使用非标准元素次序的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">web.xml</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">文件是不可移植的。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 22pt; mso-char-indent-count: 2.0"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">下面的列表给出了所有可直接出现在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">web-app</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素内的合法元素所必需的次序。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 22pt; mso-char-indent-count: 2.0"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">此列表说明</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">servlet</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素必须出现在所有</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">servlet-mapping</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素之前。请注意，所有这些元素都是可选的。因此，可以省略掉某一元素，但不能把它放于不正确的位置。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l icon icon</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素指出</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">IDE</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">和</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">GUI</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">工具用来表示</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">Web</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">应用的一个和两个图像文件的位置。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l display-name display-name</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素提供</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">GUI</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">工具可能会用来标记这个特定的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">Web</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">应用的一个名称。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l description description</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素给出与此有关的说明性文本。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l context-param context-param</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素声明应用范围内的初始化参数。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l filter </SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">过滤器元素将一个名字与一个实现</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">javax.servlet.Filter</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">接口的类相关联。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l filter-mapping </SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">一旦命名了一个过滤器，就要利用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">filter-mapping</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素把它与一个或多个</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">servlet</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">或</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">JSP</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">页面相关联。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l listener servlet API</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">的版本</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">2.3</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">增加了对事件监听程序的支持，事件监听程序在建立、修改和删除会话或</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">servlet</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">环境时得到通知。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">Listener</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素指出事件监听程序类。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l servlet </SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">在向</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">servlet</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">或</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">JSP</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">页面制定初始化参数或定制</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">URL</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">时，必须首先命名</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">servlet</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">或</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">JSP</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">页面。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">Servlet</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素就是用来完成此项任务的。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l servlet-mapping </SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">服务器一般为</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">servlet</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">提供一个缺省的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">URL</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><A href="http://host/webAppPrefix/servlet/ServletName。但是，常常会更改这个URL，以便servlet可以访问初始化参数或更容易地处理相对URL。在更改缺省URL时，使用servlet-mapping元素。" target=_blank>http://host/webAppPrefix/servlet/ServletName<SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><SPAN lang=EN-US>。但是，常常会更改这个</SPAN></SPAN>URL<SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><SPAN lang=EN-US>，以便</SPAN></SPAN>servlet<SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><SPAN lang=EN-US>可以访问初始化参数或更容易地处理相对</SPAN></SPAN>URL<SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><SPAN lang=EN-US>。在更改缺省</SPAN></SPAN>URL<SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><SPAN lang=EN-US>时，使用</SPAN></SPAN>servlet-mapping<SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><SPAN lang=EN-US>元素。</SPAN></SPAN></A><BR>l session-config </SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">如果某个会话在一定时间内未被访问，服务器可以抛弃它以节省内存。可通过使用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">HttpSession</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">setMaxInactiveInterval</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">方法明确设置单个会话对象的超时值，或者可利用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">session-config</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素制定缺省超时值。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l mime-mapping </SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">如果</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">Web</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">应用具有想到特殊的文件，希望能保证给他们分配特定的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">MIME</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">类型，则</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">mime-mapping</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素提供这种保证。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l welcom-file-list welcome-file-list</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素指示服务器在收到引用一个目录名而不是文件名的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">URL</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">时，使用哪个文件。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l error-page error-page</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素使得在返回特定</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">HTTP</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">状态代码时，或者特定类型的异常被抛出时，能够制定将要显示的页面。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l taglib taglib</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素对标记库描述符文件（</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">Tag Libraryu Descriptor file</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">）指定别名。此功能使你能够更改</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">TLD</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">文件的位置，而不用编辑使用这些文件的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">JSP</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">页面。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l resource-env-ref resource-env-ref</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素声明与资源相关的一个管理对象。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l resource-ref resource-ref</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素声明一个资源工厂使用的外部资源。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l security-constraint security-constraint</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素制定应该保护的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">URL</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">。它与</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">login-config</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素联合使用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l login-config </SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">login-config</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素来指定服务器应该怎样给试图访问受保护页面的用户授权。它与</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">sercurity-constraint</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素联合使用。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l security-role security-role</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素给出安全角色的一个列表，这些角色将出现在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">servlet</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素内的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">security-role-ref</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">role-name</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">子元素中。分别地声明角色可使高级</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">IDE</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">处理安全信息更为容易。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l env-entry env-entry</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素声明</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">Web</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">应用的环境项。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l ejb-ref ejb-ref</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素声明一个</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">EJB</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">的主目录的引用。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><BR>l ejb-local-ref ejb-local-ref</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">元素声明一个</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">EJB</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">的本地主目录的应用。<BR>3、</SPAN></P><img src ="http://www.blogjava.net/shmily432685/aggbug/19258.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/shmily432685/" target="_blank">闵毓</a> 2005-11-11 10:29 <a href="http://www.blogjava.net/shmily432685/archive/2005/11/11/19258.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>集成 Struts、Tiles 和 JavaServer Faces</title><link>http://www.blogjava.net/shmily432685/archive/2005/11/10/19073.html</link><dc:creator>闵毓</dc:creator><author>闵毓</author><pubDate>Wed, 09 Nov 2005 16:19:00 GMT</pubDate><guid>http://www.blogjava.net/shmily432685/archive/2005/11/10/19073.html</guid><wfw:comment>http://www.blogjava.net/shmily432685/comments/19073.html</wfw:comment><comments>http://www.blogjava.net/shmily432685/archive/2005/11/10/19073.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/shmily432685/comments/commentRss/19073.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/shmily432685/services/trackbacks/19073.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 将三种技术的功能、灵活性和可管理性集成到一起您是否想将 JavaServer Faces (JSF)的强大前端功能、Tiles 的内容格式编排优势和 Struts controller 层的灵活性都加入到您的J2EE Web 应用程序中？企业级 Java 专家 Srikanth Shenoy 和 Nithin Mallya 为您展示了如何将这三者的功能集成到一起。本文演示了如何在 Struts-F...&nbsp;&nbsp;<a href='http://www.blogjava.net/shmily432685/archive/2005/11/10/19073.html'>阅读全文</a><img src ="http://www.blogjava.net/shmily432685/aggbug/19073.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/shmily432685/" target="_blank">闵毓</a> 2005-11-10 00:19 <a href="http://www.blogjava.net/shmily432685/archive/2005/11/10/19073.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用 Spring 更好地处理 Struts 动作 三种整合 Struts 应用程序与 Spring 的方式</title><link>http://www.blogjava.net/shmily432685/archive/2005/11/09/19069.html</link><dc:creator>闵毓</dc:creator><author>闵毓</author><pubDate>Wed, 09 Nov 2005 15:53:00 GMT</pubDate><guid>http://www.blogjava.net/shmily432685/archive/2005/11/09/19069.html</guid><wfw:comment>http://www.blogjava.net/shmily432685/comments/19069.html</wfw:comment><comments>http://www.blogjava.net/shmily432685/archive/2005/11/09/19069.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/shmily432685/comments/commentRss/19069.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/shmily432685/services/trackbacks/19069.html</trackback:ping><description><![CDATA[<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR vAlign=top>
<TD width="100%"></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>
<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>
&nbsp;
<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></TD>
<TD width=122></TD></TR><NOSCRIPT><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/c.gif" height="16" width="16" alt="" /></td><td width="122" class="small"><p><span class="ast">未显示需要 JavaScript 的文档选项</span></p></td></tr></NOSCRIPT></FORM>
<TR vAlign=top>
<TD width=8><FONT face=Verdana color=#5c81a7 size=2><IMG height=1 alt="" src="http://www.ibm.com/i/c.gif" width=8></FONT></TD>
<TD width=16><FONT face=Verdana color=#5c81a7 size=2></FONT></TD>
<TD width=122>
<P>&nbsp;</P></TD></TR>
<TR vAlign=top>
<TD width=8><FONT face=Verdana color=#5c81a7 size=2><IMG height=1 alt="" src="http://www.ibm.com/i/c.gif" width=8></FONT></TD>
<TD width=16><FONT face=Verdana color=#5c81a7 size=2></FONT></TD>
<TD width=122>
<P><A class=smallplainlink href="http://www-128.ibm.com/developerworks/cn/java/j-sr2.html#download"><B><FONT face=Verdana color=#996699 size=2></FONT></B></A>&nbsp;</P></TD></TR></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></TD>
<TD width=125></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/j-sr2.html#author"><FONT color=#996699>George Franciscus </FONT></A>, 负责人, Nexcel<BR></P>
<P>2005 年 11 月 03 日</P>
<BLOCKQUOTE><I>Struts Recipes</I> 的合著者 George Franciscus 将介绍另一个重大的 Struts 整合窍门 —— 这次是将 Struts 应用程序导入 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架。请跟随 George，他将向您展示如何改变 Struts 动作，使得管理 Struts 动作就像管理 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> beans 那样。结果是一个增强的 web 框架，这个框架可以方便地利用 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> AOP 的优势。</BLOCKQUOTE>
<P>您肯定已经听说过控制反转 (IOC) 设计模式，因为很长一段时间以来一直在流传关于它的信息。如果您在任何功能中使用过 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架，那么您就知道其原理的作用。在本文中，我利用这一原理把一个 Struts 应用程序注入 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架，您将亲身体会到 IOC 模式的强大。</P>
<P>将一个 Struts 应用程序整合进 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架具有多方面的优点。首先，Spring 是为解决一些关于 JEE 的真实世界问题而设计的，比如复杂性、低性能和可测试性，等等。第二，Spring 框架包含一个 AOP 实现，允许您将面向方面技术应用于面向对象的代码。第三，一些人可能会说 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架只有<I>处理</I> Struts 比 Struts 处理自己好。但是这是观点问题，我演示三种将 Struts 应用程序整合到 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架的方法后，具体由您自己决定使用哪一种。</P>
<P>我所演示的方法都是执行起来相对简单的，但是它们却具有明显不同的优点。我为每一种方法创建了一个独立而可用的例子，这样您就可以完全理解每种方法。请参阅 <A href="http://www-128.ibm.com/developerworks/cn/java/j-sr2.html#resources"><FONT color=#996699>下载</FONT></A> 部分获得完整例子源代码。请参阅 <A href="http://www-128.ibm.com/developerworks/cn/java/j-sr2.html#resources"><FONT color=#996699>参考资料</FONT></A>，下载 Struts MVC 和 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架。</P>
<P><A name=IDAFEWW><SPAN class=atitle><STRONG><FONT size=4>为什么 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 这么了不起？</FONT></STRONG></SPAN></A></P>
<P><a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的创立者 Rod Johnson 以一种批判的眼光看待 Java™ 企业软件开发，并且提议很多企业难题都能够通过战略地使用 IOC 模式（也称作依赖注入）来解决。当 Rod 和一个具有奉献精神的开放源码开发者团队将这个理论应用于实践时，结果就产生了 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架。简言之，Spring 是一个轻型的容器，利用它可以使用一个外部 XML 配置文件方便地将对象连接在一起。每个对象都可以通过显示一个 JavaBean 属性收到一个到依赖对象的引用，留给您的简单任务就只是在一个 XML 配置文件中把它们连接好。</P>
<TABLE cellSpacing=0 cellPadding=0 width="40%" 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=5 width="100%" border=1>
<TBODY>
<TR>
<TD bgColor=#eeeeee><A name=IDAMEWW><B>IOC 和 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a></B></A><BR>
<P>IOC 是一种使应用程序逻辑外在化的设计模式，所以它是被注入而不是被写入客户机代码中。将 IOC 与接口编程应用结合，就像 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架那样，产生了一种架构，这种架构能够减少客户机对特定实现逻辑的依赖。请参阅 <A href="http://www-128.ibm.com/developerworks/cn/java/j-sr2.html#resources"><FONT color=#996699>参考资料</FONT></A> 了解更多关于 IOC 和 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的信息。</P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<P>依赖注入是一个强大的特性，但是 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架能够提供更多特性。Spring 支持可插拔的事务管理器，可以给您的事务处理提供更广泛的选择范围。它集成了领先的持久性框架，并且提供一个一致的异常层次结构。Spring 还提供了一种使用面向方面代码代替正常的面向对象代码的简单机制。</P>
<P><a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> AOP 允许您使用<I>拦截器</I> 在一个或多个执行点上拦截应用程序逻辑。加强应用程序在拦截器中的日志记录逻辑会产生一个更可读的、实用的代码基础，所以拦截器广泛用于日志记录。您很快就会看到，为了处理横切关注点，Spring AOP 发布了它自己的拦截器，您也可以编写您自己的拦截器。</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/j-sr2.html#main"><B><FONT face=Verdana color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=IDA2EWW><SPAN class=atitle><STRONG><FONT size=4>整合 Struts 和 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a></FONT></STRONG></SPAN></A></P>
<P>与 Struts 相似，Spring 可以作为一个 MVC 实现。这两种框架都具有自己的优点和缺点，尽管大部分人同意 Struts 在 MVC 方面仍然是最好的。很多开发团队已经学会在时间紧迫的时候利用 Struts 作为构造高品质软件的基础。Struts 具有如此大的推动力，以至于开发团队宁愿整合 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架的特性，而不愿意转换成 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> MVC。没必要进行转换对您来说是一个好消息。Spring 架构允许您将 Struts 作为 Web 框架连接到基于 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的业务和持久层。最后的结果就是现在一切条件都具备了。</P>
<P>在接下来的小窍门中，您将会了解到三种将 Struts MVC 整合到 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架的方法。我将揭示每种方法的缺陷并且对比它们的优点。 一旦您了解到所有三种方法的作用，我将会向您展示一个令人兴奋的应用程序，这个程序使用的是这三种方法中我最喜欢的一种。</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/j-sr2.html#main"><B><FONT face=Verdana color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=IDADFWW><SPAN class=atitle><STRONG><FONT size=4>三个小窍门</FONT></STRONG></SPAN></A></P>
<P>接下来的每种整合技术（或者窍门）都有自己的优点和特点。我偏爱其中的一种，但是我知道这三种都能够加深您对 Struts 和 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的理解。在处理各种不同情况的时候，这将给您提供一个广阔的选择范围。方法如下：</P>
<UL>
<LI>使用 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的 <CODE><FONT face=Courier size=2>ActionSupport</FONT></CODE> 类整合 Structs 
<LI>使用 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的 <CODE><FONT face=Courier size=2>DelegatingRequestProcessor</FONT></CODE> 覆盖 Struts 的 <CODE><FONT face=Courier size=2>RequestProcessor </FONT></CODE>
<LI>将 Struts <CODE><FONT face=Courier size=2>Action</FONT></CODE> 管理委托给 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架</LI></UL>
<P><A name=IDAAGWW><SPAN class=smalltitle><STRONG>装载应用程序环境</STRONG></SPAN></A></P>
<P>无论您使用哪种技术，都需要使用 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的 <CODE><FONT face=Courier size=2>ContextLoaderPlugin</FONT></CODE> 为 Struts 的 <CODE><FONT face=Courier size=2>ActionServlet</FONT></CODE> 装载 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 应用程序环境。就像添加任何其他插件一样，简单地向您的 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;plug-in className=
  "org.springframework.web.struts.ContextLoaderPlugIn"&gt;
    &lt;set-property property=
      "contextConfigLocation" value="/WEB-INF/beans.xml"/&gt;
 &lt;/plug-in&gt;
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>前面已经提到过，在 <A href="http://www-128.ibm.com/developerworks/cn/java/j-sr2.html#download"><FONT color=#996699>下载</FONT></A> 部分，您能够找到这三个完全可使用的例子的完整源代码。每个例子都为一个书籍搜索应用程序提供一种不同的 Struts 和 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的整合方法。您可以在这里看到例子的要点，但是您也可以下载应用程序以查看所有的细节。</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/j-sr2.html#main"><B><FONT face=Verdana color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=IDAZGWW><SPAN class=atitle><STRONG><FONT size=4>窍门 1. 使用 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的 ActionSupport</FONT></STRONG></SPAN></A></P>
<P>手动创建一个 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 环境是一种整合 Struts 和 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的最直观的方式。为了使它变得更简单，Spring 提供了一些帮助。为了方便地获得 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 环境，<CODE><FONT face=Courier size=2>org.springframework.web.struts.ActionSupport</FONT></CODE> 类提供了一个 <CODE><FONT face=Courier size=2>getWebApplicationContext()</FONT></CODE> 方法。您所做的只是从 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的 <CODE><FONT face=Courier size=2>ActionSupport</FONT></CODE> 而不是 Struts <CODE><FONT face=Courier size=2>Action</FONT></CODE> 类扩展您的动作，如清单 1 所示：</P><BR><A name=IDAUHWW><B>清单 1. 使用 ActionSupport 整合 Struts</B></A><BR>
<TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">package ca.nexcel.books.actions;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import org.springframework.context.ApplicationContext;
import org.springframework.web.struts.ActionSupport;

import ca.nexcel.books.beans.Book;
import ca.nexcel.books.business.BookService;

public class SearchSubmit extends ActionSupport {   <SPAN class=boldcode><STRONG>|(1)</STRONG></SPAN>


  public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException {

    DynaActionForm searchForm = (DynaActionForm) form;
    String isbn = (String) searchForm.get("isbn");
		
    //the old fashion way
    //BookService bookService = new BookServiceImpl();
		
    ApplicationContext ctx = 
      getWebApplicationContext();    <SPAN class=boldcode><STRONG>|(2)</STRONG></SPAN>
    BookService bookService = 
      (BookService) ctx.getBean("bookService");   <SPAN class=boldcode><STRONG>|(3)</STRONG></SPAN>
        
  Book book = bookService.read(isbn.trim());

    if (null == book) {
      ActionErrors errors = new ActionErrors();
      errors.add(ActionErrors.GLOBAL_ERROR,new ActionError
        ("message.notfound"));
      saveErrors(request, errors);
      return mapping.findForward("failure") ;
  }

    request.setAttribute("book", book);
    return mapping.findForward("success");
  }
}
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>让我们快速思考一下这里到底发生了什么。在 (1) 处，我通过从 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的 <CODE><FONT face=Courier size=2>ActionSupport</FONT></CODE> 类而不是 Struts 的 <CODE><FONT face=Courier size=2>Action</FONT></CODE> 类进行扩展，创建了一个新的 <CODE><FONT face=Courier size=2>Action</FONT></CODE>。在 (2) 处，我使用 <CODE><FONT face=Courier size=2>getWebApplicationContext()</FONT></CODE> 方法获得一个 <CODE><FONT face=Courier size=2>ApplicationContext</FONT></CODE>。为了获得业务服务，我使用在 (2) 处获得的环境在 (3) 处查找一个 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> bean。</P>
<P>这种技术很简单并且易于理解。不幸的是，它将 Struts 动作与 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架耦合在一起。如果您想替换掉 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a>，那么您必须重写代码。并且，由于 Struts 动作不在 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的控制之下，所以它不能获得 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> AOP 的优势。当使用多重独立的 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 环境时，这种技术可能有用，但是在大多数情况下，这种方法不如另外两种方法合适。</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/j-sr2.html#main"><B><FONT face=Verdana color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=IDA0A4W><SPAN class=atitle><STRONG><FONT size=4>窍门 2. 覆盖 RequestProcessor</FONT></STRONG></SPAN></A></P>
<P>将 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 从 Struts 动作中分离是一个更巧妙的设计选择。分离的一种方法是使用 <CODE><FONT face=Courier size=2>org.springframework.web.struts.DelegatingRequestProcessor</FONT></CODE> 类来覆盖 Struts 的 <CODE><FONT face=Courier size=2>RequestProcessor</FONT></CODE> 处理程序，如清单 2 所示：</P><BR><A name=IDANB4W><B>清单 2. 通过 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的 DelegatingRequestProcessor 进行整合</B></A><BR>
<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 struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
          "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"&gt;

&lt;struts-config&gt;
 &lt;form-beans&gt;
    &lt;form-bean name="searchForm" 
      type="org.apache.struts.validator.DynaValidatorForm"&gt;
               &lt;form-property name="isbn"    type="java.lang.String"/&gt;
    &lt;/form-bean&gt;
  
  &lt;/form-beans&gt;

 &lt;global-forwards type="org.apache.struts.action.ActionForward"&gt;
     &lt;forward   name="welcome"                path="/welcome.do"/&gt;
     &lt;forward   name="searchEntry"            path="/searchEntry.do"/&gt;
     &lt;forward   name="searchSubmit"           path="/searchSubmit.do"/&gt;
 &lt;/global-forwards&gt;

 &lt;action-mappings&gt;
    &lt;action    path="/welcome" forward="/WEB-INF/pages/welcome.htm"/&gt;
    &lt;action    path="/searchEntry" forward="/WEB-INF/pages/search.jsp"/&gt;
    &lt;action    path="/searchSubmit" 
               type="ca.nexcel.books.actions.SearchSubmit"
               input="/searchEntry.do"
               validate="true"
               name="searchForm"&gt;
              &lt;forward name="success" path="/WEB-INF/pages/detail.jsp"/&gt;
              &lt;forward name="failure" path="/WEB-INF/pages/search.jsp"/&gt;
    &lt;/action&gt;  

 &lt;/action-mappings&gt;

 &lt;message-resources parameter="ApplicationResources"/&gt;

 &lt;controller processorClass="org.springframework.web.struts.
   DelegatingRequestProcessor"/&gt; <SPAN class=boldcode><STRONG>|(1)</STRONG></SPAN>

 &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;


 &lt;plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"&gt;
    &lt;set-property property="csntextConfigLocation" value="/WEB-INF/beans.xml"/&gt;
 &lt;/plug-in&gt;
 
&lt;/struts-config&gt;
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>我利用了 <CODE><FONT face=Courier size=2>&lt;controller&gt;</FONT></CODE> 标记来用 <CODE><FONT face=Courier size=2>DelegatingRequestProcessor</FONT></CODE> 覆盖默认的 Struts <CODE><FONT face=Courier size=2>RequestProcessor</FONT></CODE>。下一步是在我的 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 配置文件中注册该动作，如清单 3 所示：</P><BR><A name=IDAGC4W><B>清单 3. 在 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 配置文件中注册一个动作</B></A><BR>
<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="UTF-8"?&gt;
&lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
  "http://www.springframework.org/dtd/spring-beans.dtd"&gt;

&lt;beans&gt;
  &lt;bean id="bookService" class="ca.nexcel.books.business.BookServiceImpl"/&gt;

  &lt;bean name="/searchSubmit" 
    class="ca.nexcel.books.actions.SearchSubmit"&gt; <SPAN class=boldcode><STRONG>|(1)</STRONG></SPAN>
     &lt;property name="bookService"&gt;
        &lt;ref bean="bookService"/&gt;
     &lt;/property&gt;
  &lt;/bean&gt;
&lt;/beans&gt;
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>注意：在 (1) 处，我使用名称属性注册了一个 bean，以匹配 struts-config 动作映射名称。<CODE><FONT face=Courier size=2>SearchSubmit</FONT></CODE> 动作揭示了一个 JavaBean 属性，允许 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 在运行时填充属性，如清单 4 所示：</P><BR><A name=IDAXC4W><B>清单 4. 具有 JavaBean 属性的 Struts 动作</B></A><BR>
<TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">package ca.nexcel.books.actions;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

import ca.nexcel.books.beans.Book;
import ca.nexcel.books.business.BookService;

public class SearchSubmit extends Action {
	
  private BookService bookService;
  public BookService getBookService() {
    return bookService;
  }

  public void setBookService(BookService bookService) { <SPAN class=boldcode><STRONG>| (1)</STRONG></SPAN>
    this.bookService = bookService; 
  } 

  public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException {

    DynaActionForm searchForm = (DynaActionForm) form;
    String isbn = (String) searchForm.get("isbn");
		
  Book book = getBookService().read(isbn.trim());  <SPAN class=boldcode><STRONG>|(2)</STRONG></SPAN>

    if (null == book) {
      ActionErrors errors = new ActionErrors();
      errors.add(ActionErrors.GLOBAL_ERROR,new ActionError("message.notfound"));
      saveErrors(request, errors);
      return mapping.findForward("failure") ;
  }

      request.setAttribute("book", book);
      return mapping.findForward("success");
  }

}
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>在清单 4 中，您可以了解到如何创建 Struts 动作。在 (1) 处，我创建了一个 JavaBean 属性。<CODE><FONT face=Courier size=2>DelegatingRequestProcessor</FONT></CODE>自动地配置这种属性。这种设计使 Struts 动作并不知道它正被 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 管理，并且使您能够利用 Sping 的动作管理框架的所有优点。由于您的 Struts 动作注意不到 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的存在，所以您不需要重写您的 Struts 代码就可以使用其他控制反转容器来替换掉 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a>。</P>
<P><CODE><FONT face=Courier size=2>DelegatingRequestProcessor</FONT></CODE> 方法的确比第一种方法好，但是仍然存在一些问题。如果您使用一个不同的 <CODE><FONT face=Courier size=2>RequestProcessor</FONT></CODE>，则需要手动整合 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的 <CODE><FONT face=Courier size=2>DelegatingRequestProcessor</FONT></CODE>。添加的代码会造成维护的麻烦并且将来会降低您的应用程序的灵活性。此外，还有过一些使用一系列命令来代替 Struts <CODE><FONT face=Courier size=2>RequestProcessor</FONT></CODE> 的传闻。 这种改变将会对这种解决方法的使用寿命造成负面的影响。</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/j-sr2.html#main"><B><FONT face=Verdana color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=IDAYD4W><SPAN class=atitle><STRONG><FONT size=4>窍门 3. 将动作管理委托给 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a></FONT></STRONG></SPAN></A></P>
<P>一个更好的解决方法是将 Strut 动作管理委托给 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a>。您可以通过在 <CODE><FONT face=Courier size=2>struts-config</FONT></CODE> 动作映射中注册一个代理来实现。代理负责在 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 环境中查找 Struts 动作。由于动作在 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的控制之下，所以它可以填充动作的 JavaBean 属性，并为应用诸如 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的 AOP 拦截器之类的特性带来了可能。 </P>
<P>清单 5 中的 <CODE><FONT face=Courier size=2>Action</FONT></CODE> 类与清单 4 中的相同。但是 struts-config 有一些不同：</P><BR><A name=IDANE4W><B>清单 5. <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 整合的委托方法</B></A><BR>
<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 struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
          "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"&gt;

&lt;struts-config&gt;
 &lt;form-beans&gt;
    &lt;form-bean name="searchForm" 
      type="org.apache.struts.validator.DynaValidatorForm"&gt;
               &lt;form-property name="isbn"    type="java.lang.String"/&gt;
    &lt;/form-bean&gt;
  
  &lt;/form-beans&gt;

 &lt;global-forwards type="org.apache.struts.action.ActionForward"&gt;
     &lt;forward   name="welcome"                path="/welcome.do"/&gt;
     &lt;forward   name="searchEntry"            path="/searchEntry.do"/&gt;
     &lt;forward   name="searchSubmit"           path="/searchSubmit.do"/&gt;
 &lt;/global-forwards&gt;

 &lt;action-mappings&gt;
    &lt;action    path="/welcome" forward="/WEB-INF/pages/welcome.htm"/&gt;
    &lt;action    path="/searchEntry" forward="/WEB-INF/pages/search.jsp"/&gt;
    &lt;action    path="/searchSubmit" 
             type="org.springframework.web.struts.DelegatingActionProxy" <SPAN class=boldcode><STRONG>|(1)</STRONG></SPAN>
             input="/searchEntry.do"
             validate="true"
             name="searchForm"&gt;
             &lt;forward name="success" path="/WEB-INF/pages/detail.jsp"/&gt;
             &lt;forward name="failure" path="/WEB-INF/pages/search.jsp"/&gt;
    &lt;/action&gt;  

 &lt;/action-mappings&gt;

 &lt;message-resources parameter="ApplicationResources"/&gt;


 &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;


 &lt;plug-in 
    className="org.springframework.web.struts.ContextLoaderPlugIn"&gt;
    &lt;set-property property="contextConfigLocation" value="/WEB-INF/beans.xml"/&gt;
 &lt;/plug-in&gt;

 
&lt;/struts-config&gt;
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>清单 5 是一个典型的 struts-config.xml 文件，只有一个小小的差别。它注册 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 代理类的名称，而不是声明动作的类名，如（1）处所示。DelegatingActionProxy 类使用动作映射名称查找 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 环境中的动作。这就是我们使用 <CODE><FONT face=Courier size=2>ContextLoaderPlugIn</FONT></CODE> 声明的环境。</P>
<P>将一个 Struts 动作注册为一个 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> bean 是非常直观的，如清单 6 所示。我利用动作映射使用 <CODE><FONT face=Courier size=2>&lt;bean&gt;</FONT></CODE> 标记的名称属性（在这个例子中是 "<CODE><FONT face=Courier size=2>/searchSubmit</FONT></CODE>"）简单地创建了一个 bean。这个动作的 JavaBean 属性像任何 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> bean 一样被填充： </P><BR><A name=IDAIF4W><B>清单 6. 在 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 环境中注册一个 Struts 动作</B></A><BR>
<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="UTF-8"?&gt;
&lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
 "http://www.springframework.org/dtd/spring-beans.dtd"&gt;

&lt;beans&gt;
  &lt;bean id="bookService" class="ca.nexcel.books.business.BookServiceImpl"/&gt;

  &lt;bean name="/searchSubmit"   
        class="ca.nexcel.books.actions.SearchSubmit"&gt;
     &lt;property name="bookService"&gt;
        &lt;ref bean="bookService"/&gt;
     &lt;/property&gt;
  &lt;/bean&gt;

&lt;/beans&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%"></FONT></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><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/j-sr2.html#main"><B><FONT face=Verdana color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=IDAOF4W><SPAN class=atitle><STRONG><FONT size=4>动作委托的优点</FONT></STRONG></SPAN></A></P>
<P>动作委托解决方法是这三种方法中最好的。Struts 动作不了解 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a>，不对代码作任何改变就可用于非 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 应用程序中。<CODE><FONT face=Courier size=2>RequestProcessor</FONT></CODE> 的改变不会影响它，并且它可以利用 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> AOP 特性的优点。 </P>
<P>动作委托的优点不止如此。一旦让 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 控制您的 Struts 动作，您就可以使用 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 给动作补充更强的活力。例如，没有 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的话，所有的 Struts 动作都必须是线程安全的。如果您设置 <CODE><FONT face=Courier size=2>&lt;bean&gt;</FONT></CODE> 标记的 singleton 属性为“false”，那么不管用何种方法，您的应用程序都将在每一个请求上有一个新生成的动作对象。您可能不需要这种特性，但是把它放在您的工具箱中也很好。您也可以利用 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的生命周期方法。例如，当实例化 Struts 动作时，<CODE><FONT face=Courier size=2>&lt;bean&gt;</FONT></CODE> 标记的 init-method 属性被用于运行一个方法。类似地，在从容器中删除 bean 之前，destroy-method 属性执行一个方法。这些方法是管理昂贵对象的好办法，它们以一种与 Servlet 生命周期相同的方式进行管理。</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/j-sr2.html#main"><B><FONT face=Verdana color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=IDAEG4W><SPAN class=atitle><STRONG><FONT size=4>拦截 Struts</FONT></STRONG></SPAN></A></P>
<P>前面提到过，通过将 Struts 动作委托给 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架而整合 Struts 和 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的一个主要的优点是：您可以将 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的 AOP 拦截器应用于您的 Struts 动作。通过将 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 拦截器应用于 Struts 动作，您可以用最小的代价处理横切关注点。</P>
<P>虽然 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 提供很多内置拦截器，但是我将向您展示如何创建自己的拦截器并把它应用于一个 Struts 动作。为了使用拦截器，您需要做三件事：</P>
<OL>
<LI>创建拦截器。 
<LI>注册拦截器。 
<LI>声明在何处拦截代码。</LI></OL>
<P>这看起来非常简单的几句话却非常强大。例如，在清单 7 中，我为 Struts 动作创建了一个日志记录拦截器。 这个拦截器在每个方法调用之前打印一句话：</P><BR><A name=IDAUG4W><B>清单 7. 一个简单的日志记录拦截器</B></A><BR>
<TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">package ca.nexcel.books.interceptors;

import org.springframework.aop.MethodBeforeAdvice;

import java.lang.reflect.Method;

public class LoggingInterceptor implements MethodBeforeAdvice {

   public void before(Method method, Object[] objects, Object o) throws Throwable {
        System.out.println("logging before!");
    }
}
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>这个拦截器非常简单。<CODE><FONT face=Courier size=2>before()</FONT></CODE> 方法在拦截点中每个方法之前运行。在本例中，它打印出一句话，其实它可以做您想做的任何事。下一步就是在 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 配置文件中注册这个拦截器，如清单 8 所示：</P><BR><A name=IDADH4W><B>清单 8. 在 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 配置文件中注册拦截器</B></A><BR>
<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="UTF-8"?&gt;
&lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
  "http://www.springframework.org/dtd/spring-beans.dtd"&gt;

&lt;beans&gt;
  &lt;bean id="bookService" class="ca.nexcel.books.business.BookServiceImpl"/&gt;

  &lt;bean name="/searchSubmit" 
        class="ca.nexcel.books.actions.SearchSubmit"&gt;
     &lt;property name="bookService"&gt;
        &lt;ref bean="bookService"/&gt;
     &lt;/property&gt;
  &lt;/bean&gt;

  &lt;!--  Interceptors --&gt; 
  &lt;bean name="logger"    
    class="ca.nexcel.books.interceptors.LoggingInterceptor"/&gt; <SPAN class=boldcode><STRONG>|(1)</STRONG></SPAN>

  &lt;!-- AutoProxies --&gt;
  &lt;bean name="loggingAutoProxy" 
        class="org.springframework.aop.framework.autoproxy.
          BeanNameAutoProxyCreator"&gt; <SPAN class=boldcode><STRONG>|(2)</STRONG></SPAN>
    &lt;property name="beanNames"&gt;
          &lt;value&gt;/searchSubmit&lt;/valuesgt; <SPAN class=boldcode><STRONG>|(3)</STRONG></SPAN>
    &lt;/property&gt;
    &lt;property name="interceptorNames"&gt;
        &lt;list&gt;
          &lt;value&gt;logger&lt;/value&gt; <SPAN class=boldcode><STRONG>|(4)</STRONG></SPAN>
        &lt;/list&gt;
    &lt;/property&gt;
   &lt;/bean&gt;

&lt;/beans&gt;
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>您可能已经注意到了，清单 8 扩展了 <A href="http://www-128.ibm.com/developerworks/cn/java/j-sr2.html#code6"><FONT color=#996699>清单 6</FONT></A> 中所示的应用程序以包含一个拦截器。具体细节如下：</P>
<UL>
<LI>在 (1) 处，我注册了这个拦截器。 
<LI>在 (2) 处，我创建了一个 bean 名称自动代理，它描述如何应用拦截器。还有其他的方法定义拦截点，但是这种方法常见而简便。 
<LI>在 (3) 处，我将 Struts 动作注册为将被拦截的 bean。如果您想要拦截其他的 Struts 动作，则只需要在 "beanNames" 下面创建附加的 <CODE><FONT face=Courier size=2>&lt;value&gt;</FONT></CODE> 标记。 
<LI>在 (4) 处，当拦截发生时，我执行了在 (1) 处创建的拦截器 bean 的名称。这里列出的所有拦截器都应用于“beanNames”。</LI></UL>
<P>就是这样。就像这个例子所展示的，将您的 Struts 动作置于 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架的控制之下，为处理您的 Struts 应用程序提供了一系列全新的选择。在本例中，使用动作委托可以轻松地利用 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 拦截器提高 Struts 应用程序中的日志记录能力。</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/j-sr2.html#main"><B><FONT face=Verdana color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=IDAFI4W><SPAN class=atitle><STRONG><FONT size=4>结束语</FONT></STRONG></SPAN></A></P>
<P>在本文中，您已经学习了将 Struts 动作整合到 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架中的三种窍门。使用 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的 <CODE><FONT face=Courier size=2>ActionSupport</FONT></CODE> 来整合 Struts（第一种窍门中就是这样做的）简单而快捷，但是会将 Struts 动作与 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架耦合在一起。如果您需要将应用程序移植到一个不同的框架，则需要重写代码。第二种解决方法通过委托 <CODE><FONT face=Courier size=2>RequestProcessor</FONT></CODE> 巧妙地解开代码的耦合，但是它的可扩展性不强，并且当 Struts 的 <CODE><FONT face=Courier size=2>RequestProcessor</FONT></CODE> 变成一系列命令时，这种方法就持续不了很长时间。第三种方法是这三种方法中最好的：将 Struts 动作委托给 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架可以使代码解耦，从而使您可以在您的 Struts 应用程序中利用 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 的特性（比如日志记录拦截器）。</P>
<P>三种 Struts-Spring 整合窍门中的每一种都被实现成一个完整可用的应用程序。请参阅 <A href="http://www-128.ibm.com/developerworks/cn/java/j-sr2.html#download"><FONT color=#996699>下载</FONT></A> 部分仔细研究它们。</P><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/j-sr2.html#main"><B><FONT face=Verdana color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><SPAN class=atitle><A name=download><STRONG><FONT size=4>下载</FONT></STRONG></A></SPAN></P>
<TABLE class=data-table-1 cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TH>描述</TH>
<TH>名字</TH>
<TH style="TEXT-ALIGN: right">大小</TH>
<TH>&nbsp;下载方法</TH></TR>
<TR>
<TD class=tb-row>ActionSupport sample code</TD>
<TD noWrap>j-sr2-actionsupport.zip</TD>
<TD style="TEXT-ALIGN: right" noWrap>5 MB</TD>
<TD noWrap>&nbsp;<A class=fbox href="ftp://www6.software.ibm.com/software/developer/library/j-sr2-actionsupport.zip"><B><FONT face=Verdana color=#5c81a7>FTP</FONT></B></A></TD></TR>
<TR>
<TD class=tb-row>RequestProcessor sample code</TD>
<TD noWrap>j-sr2-requestprocessor.zip</TD>
<TD style="TEXT-ALIGN: right" noWrap>5 MB</TD>
<TD noWrap>&nbsp;<A class=fbox href="ftp://www6.software.ibm.com/software/developer/library/j-sr2-requestprocessor.zip"><B><FONT face=Verdana color=#5c81a7>FTP</FONT></B></A></TD></TR>
<TR>
<TD class=tb-row>Delegate sample code</TD>
<TD noWrap>j-sr2-delegate.zip</TD>
<TD style="TEXT-ALIGN: right" noWrap>5 MB</TD>
<TD noWrap>&nbsp;<A class=fbox href="ftp://www6.software.ibm.com/software/developer/library/j-sr2-delegate.zip"><B><FONT face=Verdana color=#5c81a7>FTP</FONT></B></A></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR vAlign=top>
<TD colSpan=5><FONT face=Verdana color=#5c81a7><IMG height=12 alt="" src="http://www.ibm.com/i/c.gif" width=12 border=0></FONT></TD></TR>
<TR>
<TD><FONT face=Verdana color=#5c81a7><IMG height=16 alt="" src="http://www.ibm.com/i/v14/icons/fw.gif" width=16></FONT></TD>
<TD><A class=fbox href="http://www-128.ibm.com/developerworks/cn/whichmethod.html"><FONT face=Verdana color=#5c81a7>关于下载方法的信息</FONT></A></TD>
<TD><FONT face=Verdana color=#5c81a7><IMG height=1 alt="" src="http://www.ibm.com/i/c.gif" width=50></FONT></TD>
<TD><FONT face=Verdana color=#5c81a7><IMG height=16 alt="" src="http://www.ibm.com/i/v14/icons/sout.gif" width=16></FONT></TD>
<TD><A class=fbox href="http://www.adobe.com/products/acrobat/readstep2.html"><FONT face=Verdana color=#5c81a7>获取 Adobe® Reader®</FONT></A></TD></TR></TBODY></TABLE><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD><FONT face=Verdana color=#5c81a7><IMG height=1 alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%"></FONT></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><FONT face=Verdana color=#5c81a7><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/j-sr2.html#main"><B><FONT face=Verdana color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=resources><SPAN class=atitle><STRONG><FONT size=4>参考资料 </FONT></STRONG></SPAN></A></P><STRONG>学习</STRONG><BR>
<UL>
<LI>您可以参阅本文在 developerWorks 全球站点上的 <A href="http://www-128.ibm.com/developerworks/java/library/j-sr2.html" target=_blank><FONT color=#5c81a7>英文原文</FONT></A>。<BR><BR>
<LI><A href="http://www.ibm.com/developerworks/library/wa-spring1/"><FONT color=#5c81a7><a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 系列</FONT></A>（Naveen Balani，developerWorks，2005 年 6 到 9 月）：对 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架的组件和特性（包括 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> AOP）的分为四部分的介绍。<BR><BR>
<LI><A href="http://www.ibm.com/developerworks/web/library/wa-struts/index.html"><FONT color=#5c81a7>Best practices in Struts development</FONT></A>（Palaniyappan Thiagarajan 和 Pagadala Suresh，developerWorks，2004 年 6 月）：概述了 Struts <CODE><FONT face=Courier size=2>Action</FONT></CODE> 组件。<BR><BR>
<LI><A href="http://www.martinfowler.com/articles/injection.html"><FONT color=#5c81a7>Inversion of Control Containers and the Dependency Injection pattern</FONT></A>（Martin Fowler，2004 年 1 月）：介绍 IOC 容器。<BR><BR>
<LI><A href="http://www.theserverside.com/articles/article.tss?l=SpringFramework"><FONT color=#5c81a7>Introduction to the <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> Framework</FONT></A>（Rod Johnson，The ServerSide，2005 年 5 月）：Spring 的创立者解释了为什么 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架很重要。<BR><BR>
<LI><A href="http://www.manning.com/franciscus"><FONT color=#5c81a7>Struts Recipes</FONT></A>（George Franciscus 和 Danilo Gurovich；Manning，2004 年）：关于 Struts 窍门和最佳实践的一个流行的纲要。<BR><BR>
<LI><A href="http://www.manning.com/husted"><FONT color=#5c81a7>Struts In Action</FONT></A>（Ted Husted、Cedric Dumoulin、George Franciscus、David Winterfeldt；Manning，2002 年）：针对专业 Struts 开发人员的综合资源。<BR><BR>
<LI><A href="http://www.manning.com/walls2"><FONT color=#5c81a7><a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> In Action</FONT></A>（Craig Walls 和 Ryan Breidenbach；Manning，2005 年）：一本用于开发人员的 <a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 资源书籍。<BR><BR>
<LI><A href="http://www.ibm.com/developerworks/cn/java/"><FONT color=#5c81a7>Java 技术专区</FONT></A>：找到关于 Java 编程各个方面的文章。<BR><BR></LI></UL><BR><B>获得产品和技术</B><BR>
<UL>
<LI><A href="http://struts.apache.org/"><FONT color=#5c81a7>Struts 框架</FONT></A>：Apache Software Foundation 的一个项目。<BR><BR>
<LI><A href="http://www.springframework.org/"><FONT color=#5c81a7><a title="心得与体会" href="http://www.blogjava.net/shmily432685" >spring in action</a> 框架</FONT></A>：一个分层的 Java 企业应用程序框架。<BR><BR></LI></UL><BR><B>讨论</B><BR>
<UL>
<LI>加入本文的<A href="javascript:void forumWindow()"><FONT color=#5c81a7>论坛</FONT></A> 。(您也可以通过点击文章顶部或者底部的论坛链接参加讨论。)<BR><BR>
<LI><A href="http://www.ibm.com/developerworks/blogs/"><FONT color=#5c81a7>developerWorks blogs</FONT></A>：加入 developerWorks 社区。</LI></UL><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><BR></TD>
<TD vAlign=top align=right><A class=fbox href="http://www-128.ibm.com/developerworks/cn/java/j-sr2.html#main"><B><FONT face=Verdana color=#996699></FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<P><A name=author><SPAN class=atitle><STRONG><FONT size=4>关于作者</FONT></STRONG></SPAN></A></P>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD colSpan=2><STRONG><FONT size=4><IMG height=5 alt="" src="http://www.ibm.com/i/c.gif" width="100%"></FONT></STRONG></TD></TR>
<TR vAlign=top align=left>
<TD>
<P><STRONG><FONT size=4></FONT></STRONG></P></TD>
<TD>
<P>George Franciscus 是 Java 公司的一名顾问和 Struts 方面的权威。他是 Manning 出版的 <A href="http://www.manning.com/franciscus"><FONT color=#5c81a7>Struts Recipes</FONT></A> 和 <A href="http://www.manning.com/husted"><FONT color=#5c81a7>Struts in Action</FONT></A> 的合著者。 George 通过 <A href="http://www.nexcel.ca/"><FONT color=#5c81a7>nexcel.ca</FONT></A> 提供有关技术和管理方面的咨询服务。</P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><img src ="http://www.blogjava.net/shmily432685/aggbug/19069.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/shmily432685/" target="_blank">闵毓</a> 2005-11-09 23:53 <a href="http://www.blogjava.net/shmily432685/archive/2005/11/09/19069.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Myeclipse平台struts+hibernate+spring项目开发示例</title><link>http://www.blogjava.net/shmily432685/archive/2005/11/05/18233.html</link><dc:creator>闵毓</dc:creator><author>闵毓</author><pubDate>Fri, 04 Nov 2005 18:32:00 GMT</pubDate><guid>http://www.blogjava.net/shmily432685/archive/2005/11/05/18233.html</guid><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;<a href='http://www.blogjava.net/shmily432685/archive/2005/11/05/18233.html'>阅读全文</a><img src ="http://www.blogjava.net/shmily432685/aggbug/18233.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/shmily432685/" target="_blank">闵毓</a> 2005-11-05 02:32 <a href="http://www.blogjava.net/shmily432685/archive/2005/11/05/18233.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>