ActionSupport 为什么使用struts2

ActionSupport 类

正如前面提到的,你可以使用 WebApplicationContextUtils 类从 ServletContext 中获得WebApplicationContext 。 另一个简单的办法是继承 Spring 的 Action 类。举个例子,除了继承Struts 的 Action 之外,你也可以继承 Spring 的 ActionSupport 类。

ActionSupport 类提供了一些便利的方法,例如 getWebApplicationContext()。下面的例子展示了如何在 Action 中使用它:

Java代码
  1. publicclassUserActionextendsDispatchActionSupport{
  2. publicActionForwardexecute(ActionMappingmapping,
  3. ActionFormform,
  4. HttpServletRequestrequest,
  5. HttpServletResponseresponse)throwsException{
  6. if(log.isDebugEnabled()){
  7. log.debug("entering'delete'method...");
  8. }
  9. WebApplicationContextctx=getWebApplicationContext();
  10. UserManagermgr=(UserManager)ctx.getBean("userManager");
  11. //talktomanagerforbusinesslogic
  12. returnmapping.findForward("success");
  13. }
  14. }
public class UserAction extends DispatchActionSupport {         public ActionForward execute(ActionMapping mapping,                                    ActionForm form,                                    HttpServletRequest request,                                    HttpServletResponse response) throws Exception {           if (log.isDebugEnabled()) {               log.debug("entering 'delete' method...");           }           WebApplicationContext ctx = getWebApplicationContext();           UserManager mgr = (UserManager) ctx.getBean("userManager");           // talk to manager for business logic           return mapping.findForward("success");       }   }  

Spring 包含了所有标准 Struts Action 的子类 - Spring 版本在类名末尾附加了Support:

ActionSupport,
ActionSupport 为什么使用struts2

DispatchActionSupport,

LookupDispatchActionSupport

MappingDispatchActionSupport


你应该选择最适合你项目的集成方式。继承使得你的代码更可靠,并且你确切地知道依赖关系是如何被解析的。 另一方面,使用ContextLoaderPlugin 允许你方便地在context XML 文件里面增加新的 依赖关系。这两种集成方法,不管哪一种Spring 都提供了相当好用的选项。

  

爱华网本文地址 » http://www.aihuau.com/a/25101016/316104.html

更多阅读

mrt.exe是什么文件 autoupgrade.exe

mrt.exe是什么文件——简介网友咨询:mrt.exe 文件是什么东西?为什么使用 CPU 始终占用率很高?分享经验:这是微软的微软恶意软件删除工具,扫描的时候自然会这样!mrt.exe是什么文件——方法/步骤

dnf高级装扮兑换券怎么使用 dnf为什么没有高级装扮

dnf高级装扮兑换券怎么使用——简介 DNF装备兑换券的使用,高级,普通,稀有的都能通用dnf高级装扮兑换券怎么使用——方法/步骤dnf高级装扮兑换券怎么使用 1、在游戏中鼠标右键点击装备兑换券或者dnf高级装扮兑换券怎么使用 2、出现 d

AttributenameinvalidfortagpropertyaccordingtoTLD attribute和property

在使用Struts2中de出现以下错误:Attribute name invalid for tag property according to TLD原因:中根本就没有name这个属性存在,所以我们根据它的tld文件会给我们提供一个错误的提示。在中只有如此的四个属性,它们分别所代表的意思是:根

蛋糕油与塔塔粉转 塔塔粉可以用什么代替

蛋糕油 蛋糕油的本质是乳化剂。它是应该是一些乳化剂的混合物。乳化剂(Emulsifier)是能使食品中互不相容的油脂和不形成稳定的乳浊溶剂浊液或者乳化体系的物质。在食品添加剂手册中属于结构改良类。常见的乳化剂有单甘酯,蔗糖酯,改性大

浅谈浏览器缓存 清理浏览器缓存

为什么使用浏览器缓存 缓存存在的内容 缓存协商 缓存协商的简单演示 缓存相关的header 缓存相关header之间的关系 用户的不同操作 用户不同操作对应浏览器的不同处理方式 测试环境与线上环境取js方式不同导致的问题为什么使用本地缓

声明:《ActionSupport 为什么使用struts2》为网友梨落分享!如侵犯到您的合法权益请联系我们删除