??xml version="1.0" encoding="utf-8" standalone="yes"?>丁香婷婷久久久综合精品国产,国产精品一区毛片,国产粉嫩在线观看http://www.aygfsteel.com/iask/category/2340.html<font color='blue'>菩提本无树,明镜亦非?本来无一物,何处惹尘?lt;/font>zh-cnTue, 13 Nov 2007 05:53:15 GMTTue, 13 Nov 2007 05:53:15 GMT60整合Struts 与Springhttp://www.aygfsteel.com/iask/archive/2006/09/29/72747.html城市劣h城市劣hFri, 29 Sep 2006 03:08:00 GMThttp://www.aygfsteel.com/iask/archive/2006/09/29/72747.htmlhttp://www.aygfsteel.com/iask/comments/72747.htmlhttp://www.aygfsteel.com/iask/archive/2006/09/29/72747.html#Feedback0http://www.aygfsteel.com/iask/comments/commentRss/72747.htmlhttp://www.aygfsteel.com/iask/services/trackbacks/72747.htmlq之徒--我的博客、我的生z?/a>

1、?Spring ?ActionSupport cL?Structs 2、?Spring ?DelegatingRequestProcessor 覆盖 Struts ?RequestProcessor 3、将 Struts Action 理委托l?Spring 框架 首先要徏?装蝲应用E序环境" 无论(zhn)用哪U技术,都需要?Spring ?ContextLoaderPlugin ?Struts ?ActionServlet 装蝲 Spring 应用E序环境。就像添加Q何其他插件一P单地向?zhn)的struts-config.xml 文gd该插Ӟ如下所C: H门 1. 使用 Spring ?ActionSupport 手动创徏一?Spring 环境是一U整?Struts ?Spring 的最直观的方式。ؓ了它变得更单,Spring 提供了一些帮助。ؓ了方便地获得 Spring 环境Qorg.springframework.web.struts.ActionSupport cL供了一?getWebApplicationContext() Ҏ(gu)。?zhn)所做的只是?Spring ?ActionSupport 而不?Struts Action cL展?zhn)的动作,如清?1 所C: 清单 1. 使用 ActionSupport 整合 Struts 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 { |(1) 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(); |(2) BookService bookService = (BookService) ctx.getBean("bookService"); |(3) 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"); } } 让我们快速思考一下这里到底发生了什么。在 (1) 处,我通过?Spring ?ActionSupport c而不?Struts ?Action c进行扩展,创徏了一个新?Action。在 (2) 处,我?getWebApplicationContext() Ҏ(gu)获得一?ApplicationContext。ؓ了获得业务服务,我用在 (2) 处获得的环境?(3) 处查找一?Spring bean?q种技术很单ƈ且易于理解。不q的是,它将 Struts 动作?Spring 框架耦合在一赗如果?zhn)x换掉 SpringQ那么?zhn)必须重写代码。ƈ且,׃ Struts 动作不在 Spring 的控制之下,所以它不能获得 Spring AOP 的优ѝ当使用多重独立?Spring 环境Ӟq种技术可能有用,但是在大多数情况下,q种Ҏ(gu)不如另外两种Ҏ(gu)合适?H门 2. 覆盖 RequestProcessor ?Spring ?Struts 动作中分L一个更巧妙的设计选择。分ȝ一U方法是使用 org.springframework.web.struts.DelegatingRequestProcessor cL覆盖 Struts ?RequestProcessor 处理E序Q如清单 2 所C: 清单 2. 通过 Spring ?DelegatingRequestProcessor q行整合 |(1) 我利用了 标记来用 DelegatingRequestProcessor 覆盖默认?Struts RequestProcessor。下一步是在我?Spring 配置文g中注册该动作Q如清单 3 所C: 清单 3. ?Spring 配置文g中注册一个动?|(1) 注意Q在 (1) 处,我用名U属性注册了一?beanQ以匚w struts-config 动作映射名称。SearchSubmit 动作揭示了一?JavaBean 属性,允许 Spring 在运行时填充属性,如清?4 所C: 清单 4. h JavaBean 属性的 Struts 动作 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) { | (1) 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()); |(2) 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"); } } 在清?4 中,(zhn)可以了解到如何创徏 Struts 动作。在 (1) 处,我创Z一?JavaBean 属性。DelegatingRequestProcessor自动地配|这U属性。这U设计 Struts 动作q不知道它正?Spring 理Qƈ且(zhn)能够利?Sping 的动作管理框架的所有优炏V由于?zhn)?Struts 动作注意不到 Spring 的存在,所以?zhn)不需要重写?zhn)?Struts 代码可以用其他控制反转容器来替换?Spring?DelegatingRequestProcessor Ҏ(gu)的确比第一U方法好Q但是仍然存在一些问题。如果?zhn)使用一个不同的 RequestProcessorQ则需要手动整?Spring ?DelegatingRequestProcessor。添加的代码会造成l护的麻烦ƈ且将来会降低(zhn)的应用E序的灵zL。此外,q有q一些用一pd命o来代B?Struts RequestProcessor 的传闅R?q种改变会对这U解x法的使用寿命造成负面的媄响?H门 3. 动作管理委托给 Spring 一个更好的解决Ҏ(gu)是将 Strut 动作理委托l?Spring。?zhn)可以通过?struts-config 动作映射中注册一个代理来实现。代理负责在 Spring 环境中查?Struts 动作。由于动作在 Spring 的控制之下,所以它可以填充动作?JavaBean 属性,qؓ应用诸如 Spring ?AOP 拦截器之cȝҎ(gu)带来了可能?清单 5 中的 Action cM清单 4 中的相同。但?struts-config 有一些不同: 清单 5. Spring 整合的委托方?清单 5 是一个典型的 struts-config.xml 文gQ只有一个小的差别。它注册 Spring 代理cȝ名称Q而不是声明动作的cdQ如Q?Q处所C。DelegatingActionProxy cM用动作映名U查?Spring 环境中的动作。这是我们使用 ContextLoaderPlugIn 声明的环境?一?Struts 动作注册Z?Spring bean 是非常直观的Q如清单 6 所C。我利用动作映射使用 标记的名U属性(在这个例子中?"/searchSubmit"Q简单地创徏了一?bean。这个动作的 JavaBean 属性像M Spring bean 一栯填充Q?清单 6. ?Spring 环境中注册一?Struts 动作 动作委托的优?动作委托解决Ҏ(gu)是这三种Ҏ(gu)中最好的。Struts 动作不了?SpringQ不对代码作M改变可用于?Spring 应用E序中。RequestProcessor 的改变不会媄响它Qƈ且它可以利用 Spring AOP Ҏ(gu)的优点?动作委托的优点不止如此。一旦让 Spring 控制(zhn)的 Struts 动作Q?zhn)可以?Spring l动作补充更强的zd。例如,没有 Spring 的话Q所有的 Struts 动作都必LU程安全的。如果?zhn)讄?标记?singleton 属性ؓ"false"Q那么不用何种Ҏ(gu)Q?zhn)的应用程序都在每一个请求上有一个新生成的动作对象。?zhn)可能不需要这U特性,但是把它攑֜(zhn)的工具׃也很好。­?zhn)也可以利?Spring 的生命周期方法。例如,当实例化 Struts 动作Ӟ 标记?init-method 属性被用于q行一个方法。类似地Q在从容器中删除 bean 之前Qdestroy-method 属性执行一个方法。这些方法是理昂贵对象的好办法Q它们以一U与 Servlet 生命周期相同的方式进行管理?在本文中Q?zhn)已经学习了?Struts 动作整合?Spring 框架中的三种H门。?Spring ?ActionSupport 来整?StrutsQ第一U窍门中是q样做的Q简单而快P但是会将 Struts 动作?Spring 框架耦合在一赗如果?zhn)需要将应用E序ULC个不同的框架Q则需要重写代码。第二种解决Ҏ(gu)通过委托 RequestProcessor 巧妙地解开代码的耦合Q但是它的可扩展性不强,q且?Struts ?RequestProcessor 变成一pd命oӞq种Ҏ(gu)持l不了很长时间。第三种Ҏ(gu)是这三种Ҏ(gu)中最好的Q将 Struts 动作委托l?Spring 框架可以使代码解耦,从而(zhn)可以在(zhn)的 Struts 应用E序中利?Spring 的特性(比如日志记录拦截器)?lg所qͼ也会采用W三U方式来整合?

已经转移?q之徒--我的博客、我的生z?/a>


城市劣h 2006-09-29 11:08 发表评论
]]>
关于struts中validate的几U情?/title><link>http://www.aygfsteel.com/iask/archive/2005/08/02/9056.html</link><dc:creator>城市劣h</dc:creator><author>城市劣h</author><pubDate>Tue, 02 Aug 2005 09:51:00 GMT</pubDate><guid>http://www.aygfsteel.com/iask/archive/2005/08/02/9056.html</guid><wfw:comment>http://www.aygfsteel.com/iask/comments/9056.html</wfw:comment><comments>http://www.aygfsteel.com/iask/archive/2005/08/02/9056.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.aygfsteel.com/iask/comments/commentRss/9056.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/iask/services/trackbacks/9056.html</trackback:ping><description><![CDATA[     摘要: 已经转移?q之徒--我的博客、我的生z? Q说明)q里采用了最新版? struts-1.2.7 Q是? struts-blank 的基上演C的Qؓ了以后的学习和参考用? ...  <a href='http://www.aygfsteel.com/iask/archive/2005/08/02/9056.html'>阅读全文</a><img src ="http://www.aygfsteel.com/iask/aggbug/9056.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/iask/" target="_blank">城市劣h</a> 2005-08-02 17:51 <a href="http://www.aygfsteel.com/iask/archive/2005/08/02/9056.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank">Ӷ</a>| <a href="http://" target="_blank">°Ͷ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ͭϿ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">¸</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ػ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ʡ</a>| <a href="http://" target="_blank">Ҿ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ϰ</a>| <a href="http://" target="_blank">޳</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ľ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ǩ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>