<?xml version="1.0" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="css/rss.xslt"?>
<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>王波的博客 - 学习日志</title><link>http://www.1314lucky.cn/</link><description>幸运的笨小孩 - </description><generator>RainbowSoft Studio Z-Blog 1.8 Arwen Build 90619</generator><language>zh-CN</language><copyright>Copyright xxxx-xxxx Your WebSite. Some Rights Reserved.</copyright><pubDate>Sun, 05 Sep 2010 05:23:15 +0800</pubDate><item><title>struts2</title><author>wb8180013@163.com (lucky)</author><link>http://www.1314lucky.cn/post/34.html</link><pubDate>Tue, 08 Dec 2009 00:02:43 +0800</pubDate><guid>http://www.1314lucky.cn/post/34.html</guid><description><![CDATA[<p>时间：12月7日21：00-23：59</p><p>事件：看《struts2权威指南》电子书至35页，初步了解struts2，并参照写了一个很简单的例子。</p><p>所用Jar包：struts2-core-2.0.10.jar xwork-2.0.4.jar freemarker-2.3.8.jar ognl-2.6.11.jar</p><p>WEB容器：Tomcat6.0</p><p>练习环境：Eclipse</p><p>关键步骤：</p><p>1.WEB-INF/web.xml</p><p>&nbsp;&nbsp;&nbsp; &lt;filter&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;filter-name&gt;struts2&lt;/filter-name&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;filter-class&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; org.apache.struts2.dispatcher.FilterDispatcher<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/filter-class&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/filter&gt;<br />&nbsp;&nbsp;&nbsp; &lt;filter-mapping&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;filter-name&gt;struts2&lt;/filter-name&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/filter-mapping&gt;<br />&nbsp;&nbsp;&nbsp; &lt;welcome-file-list&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;welcome-file&gt;page/login.jsp&lt;/welcome-file&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/welcome-file-list&gt;</p><p>必须配置过滤器，并使用org.apache.struts2.dispatcher.FilterDispatcher类</p><p>2.struts.xml 源代码的根目录下</p><p>&lt;struts&gt;<br />&nbsp;&nbsp;&nbsp; &lt;include file=&quot;struts-default.xml&quot; /&gt;<br />&nbsp;&nbsp;&nbsp; &lt;package name=&quot;login&quot; extends=&quot;struts-default&quot;&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;action name=&quot;Login&quot; class=&quot;login.LoginAction&quot;&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;result name=&quot;error&quot;&gt;/page/error.jsp&lt;/result&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;result name=&quot;success&quot;&gt;/page/welcome.jsp&lt;/result&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/action&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/package&gt;<br />&lt;/struts&gt;</p><p>action节点的name属性与页面的&lt;form action=&quot;login&quot; &gt;&lt;/form&gt; 要一致。页面请求的路径，必经过Strtus2过滤器，重新分发给LoginAction.</p><p>在Struts2中获得Session和设置Session方法</p><p>ActionContext.getContext().getSession(key)</p><p>ActionContext.getContext().setSession(key,value)</p><p>struts2的最为突出的优点就是Action不再和ServletAPI耦合，LoginAction很干净，有利于代码重用和测试！而原有的Struts与ServletAPI耦合，一旦代码重构，Action层的代码，不得不废弃！</p><p>&nbsp;</p>]]></description><category>学习日志</category><comments>http://www.1314lucky.cn/post/34.html#comment</comments><wfw:comment>http://www.1314lucky.cn/</wfw:comment><wfw:commentRss>http://www.1314lucky.cn/feed.asp?cmt=34</wfw:commentRss><trackback:ping>http://www.1314lucky.cn/cmd.asp?act=tb&amp;id=34&amp;key=8e15ae2c</trackback:ping></item></channel></rss>
