建议使用DispatchAction

随着项目的发展,struts-config.xml配置文件、action、form等等都变的庞大起来,如果我们继续使用普通action,那我们就显得不明智了。建议使用DispatchAction,把相关操作集中到一个Action中,我们不用再去重新定义execute()方法。例如可以在DispatchAction中增加如下方法:

  • public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
  • public ActionForward insert(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
  • public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception

同时在struts-config.xml中定义类似的内容:

<action path="/saveSubscription" type="org.apache.struts.actions.DispatchAction" name="subscriptionForm" scope="request" input="/subscription.jsp" parameter="method"/>

其实关键是增加parameter属性。

调用方法如下:

http://localhost:8080/myapp/saveSubscription.do?method=update

记得要使用method=xx,xx代表被调用DispatchAction中的方法名

备注:建议大家去看看struts api,那里有详细的说明。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值