struts1.x Series Tutorial (20): Using the Eventdispatchaction class to handle a form multiple submit

Source: Internet
Author: User

Although the Lookupdispatchaction class can handle a form with multiple submit buttons well, it must be associated with a property file, and the mapping of key and action methods in the Getkeymethodmap method is very inconvenient to use. Starting with Struts1.2.9, another Eventdispatchaction class was added to handle multiple commit actions. This class is also a subclass of Dispatchaction, which is much easier to use than the Lookupdispatchaction class. The basic principle of the Eventdispatchaction class is to specify multiple actions by using the parameter attribute of the <action> element, separated by commas (,). Each action is actually the property value of the

We can use the Eventdispatchaction class in the following three steps.

"Step 1th" implements Eventdispatchaction subclasses

Create a Myeventdispatchaction.java file in the >\src\action directory of the <samples engineering directory with the following code:

Package action;

import Java.io.PrintWriter;
Import javax.servlet.http.*;
Import org.apache.struts.action.*;
Import org.apache.struts.actions.*;

public class Myeventdispatchaction extends Eventdispatchaction
{
//handling print actions
Pu Blic actionforward Print (actionmapping mapping, actionform form,
HttpServletRequest request, Httpservle Tresponse response)
{
Try
{
response.setcharacterencoding ("GBK ");
PrintWriter out = Response.getwriter ();
Out.println ("Print successful!");       
}
catch (Exception e)
{
}
return null;
              
//Handle Save Action
Public Actionforward Save (actionmapping mapping, actionform form,
               HttpServletRequest request, HttpServletResponse response)
{
Try
{
REsponse.setcharacterencoding ("GBK");
PrintWriter out = Response.getwriter ();
Out.println ("Save success!");       
}
catch (Exception e)
{
}
return null;
}
}

There are two methods in the Myeventdispatchaction class: Print and save, which are used to handle the request actions for the

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.