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