Sometimes the Lookupdispatchaction class comes in handy when you need to provide multiple submit buttons in an HTML form. Lookupdispatchaction is a subclass of dispatchaction that handles the case where a form in the client code contains multiple submit buttons. In order to use Lookupdispatchaction, first write the client code, the following code:
……
<bean:message key="submit.print" />
<bean:message key="submit.save" />
Where Submit.print and Submit.save are key in the properties file. The action is actually the Name property value of the Submit button. At the time of submission, the property and <bean:message key= "..."/> are passed as request parameters and parameter values to the struts action. If the Save button is clicked, the request URL is http://localhost:8080/.../myaction.do?action=save. Where save is the Submit.save property value in the property file, which means Submit.save = save.
Next we write a subclass of Lookupdispatchaction, which reads:
package action;
Import org.apache.struts.actions.LookupDispatchAction
...
public class Mylookupdispatchaction extends Lookupdispatchaction
{
//For convenience of description, the property file is not used here, just directly ke mappings for Y and value are added to the Map object
//readers can read the corresponding key-value pairs
//To add to the Map object in the Getkeymethodmap method in the dependency file
Prote CTED map Getkeymethodmap ()
{
Map m = new HashMap ();
M.put ("Submit.print", "print");
M.put ("Submit.save", "save");
return m;
}
Public Actionforward print (actionmapping mapping, actionform form,
Httpservle Trequest request, HttpServletResponse response)
{
//Processing print Code
}
Public Ac Tionforward Save (actionmapping mapping, actionform form,
HttpServletRequest request, Httpservletrespons E response)
{
//Process Save Code
}
}
When writing lookupdispatchaction subclasses, be aware that you must implement the Getkeymethodmap method, in which you need to map the key and action methods. The following code is used to configure Mylookupdispatchaction.
<action path= "/moresubmit" type= "action. Mylookupdispatchaction "parameter=" action "/>
Where the parameter property specifies the name of the request parameter that is generated by the Submit button in the request URL.