In many cases it hapens that a perticular form has more than 1 button present on it.Lets say a form has 2 buttons 1> save 2> cancel. And each of this button when pressed submits the same form.
So in order to deal with such situation and to provide the different functionality for the 2 buttons "DispatchAction" is provided.
What we do is write 2 methode named save and cancle and parameters to these 2 methodes will be the same as that of the execute methode.
So whenever we click on any of the 2 button , the perticular method(save or cancel) will gets called.Thus the moral of the story is "Dispatch Action" is ment to provide the different functionality to more than 1 button which is on the same form.
code for the Dispatch action is as
If your website is in English and you're not planning to use internatoinalization, you would code the three buttons:
<html:submit property="action">save</html:submit>
<html:submit property="action">cancel</html:submit>
You could then use DispatchAction and code the methods save(), cancel(), and
Struts would forward to the appropriate method based on the button pressed.
The LookUpDispatchAction is just the extention of the same.It is used for the internationalisation purpose. If you use internationalization, this won't work because the label of the button could be in any number of languages. In this case, you need to use LookupDispatch action and code your
JSP like this:
<html:submit property="action"><bean:message key="label.save" /></html:submit>
<html:submit property="action"><bean:message key="label.cancel/></html:submit>
You'll then code the getMethodKey() to find the appropriate method based on the message key. That way, regardless of what language is actually used at runtime, Struts will still dispatch to the correct method.