Struts_DispatchAction简单的例子

 

DispatchAction是Action类的子类,它可以将用户的请求分派到一个公共的方法中处理。下面通过一个例子来加以说明:

我引用的是struts1.1

一。创建MyJsp.jsp

 <body>体中添加:

 <a href="modify.do?method=add">add</a>
    <a href="modify.do?method=update">update</a>

二。配置struts-config.xml

 <action-mappings>
  <action path="/modify"
  parameter="method"
   type="com.nalis.struts.action.ModifyAction" />

</action-mappings>

三。创建Action (要继承org.apache.struts.actions.DispatchAction)

  不要在DispatchAction的子类重写execute方法,即删除掉TestCaseAction中的execute方法,添加add,update方法:

public ActionForward update(

        ActionMapping mapping,
        ActionForm form,
        HttpServletRequest request,
        HttpServletResponse response) {
System.out.println("update");
               return null;
    }
    public ActionForward add(
            ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response) {
        System.out.println("add");
                   return null;
        }

优点:将多个简单的处理方法放置到一个Action中,简化应用程序的设计,开发和维护。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值