Struts中的LookupDispatchAction类的具体用法

 我来答
xifo
2008-09-21 · TA获得超过898个赞
知道小有建树答主
回答量:325
采纳率:0%
帮助的人:318万
展开全部
简单地讲,它具备这样一个功能:可能根据被提交表单中你所点击的提交按钮名称,自动分发对应的处理方法,比如可轿旦以通过点击一个名称为add的提交按钮,触发一个Action的add方法,但你点击名为remove的提交宏帆禅按钮,又可以触发同一个Action的remove方法。个人认为使用价值不高,完全可以通过JS和DispatchAction实现类似功能。

下面是官方的使用示例:
public abstract class LookupDispatchAction
extends DispatchAction

An abstract Action that dispatches to the subclass mapped execute method. This is useful in cases where an HTML form has multiple submit buttons with the same name. The button name is specified by the parameter property of the corresponding ActionMapping. To configure the use of this action in your struts-config.xml file, create an entry like this:

<action path="/test"
type="org.example.MyAction"
name="MyForm"
scope="request"
input="/test.jsp"
parameter="method"/>

which will use the value of the request parameter named "method" to locate the corresponding key in ApplicationResources. For example, you might have the following ApplicationResources.properties:

button.add=Add Record
button.delete=Delete Record

And your JSP would have the following format for submit buttons:

<html:form action="/test">
<蔽尘html:submit property="method">
<bean:message key="button.add"/>
</html:submit>
<html:submit property="method">
<bean:message key="button.delete"/>
</html:submit>
</html:form>

Your subclass must implement both getKeyMethodMap and the methods defined in the map. An example of such implementations are:

protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("button.add", "add");
map.put("button.delete", "delete");
return map;
}

public ActionForward add(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// do add
return mapping.findForward("success");
}

public ActionForward delete(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// do delete
return mapping.findForward("success");
}

Notes - If duplicate values exist for the keys returned by
getKeys, only the first one found will be returned. If no corresponding key
is found then an exception will be thrown. You can override the
method unspecified to provide a custom handler. If the submit
was cancelled (a html:cancel button was pressed), the custom
handler cancelled will be used instead.
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式