struts1.x Series Tutorials: Lookupdispatchaction class handles a form multiple submit

Source: Internet
Author: User
Tags html form

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.