Dispatchaction is inherited from the action class. It is an abstract class that encapsulates some basic methods to solve the problem of using an action to process multiple operations. This is the biggest purpose of dispatchaction, it can help us use an action class to encapsulate a set of similar operation methods, saving the number of classes and reducing the difficulty of later maintenance.
Dispatchaction mainly includes the following methods:
Protected actionforwardDispatchmethod
Protected java. Lang. Reflect. MethodGetmethod
Protected java. Lang. StringGetmethodname
The configuration of the dispatchaction is slightly different from that of the standard action, that is, to add a parametr attribute in the action configuration. This attribute guides the dispatchaction to find the corresponding method. For example, the configuration is as follows:
<Action Path = "/savesub.pdf"
Type = "org. Apache. Struts. Actions. dispatchaction"
Name = "subscriptionform" Scope = "request" input = "/subscribe. jsp"
Parameter = "method"/>
Parameter attribute values can be set to any value, as long as you remember to unify the parameter values. For example, I wrote an action like this, which inherits from the dispatchaction class and contains three operation methods: add (), update (), and delete (). When I want to call the update operation of this action, the submitted URL should be similar to the following:
Http: // localhost: 8080/MyApp/savesub.pdf. do? Method = Update
It's that simple, but we have a lot to do.ProgramI feel a lot saved in development.CodeAt least the previous three class files are now one class, and it is much easier to maintain them later.
Note that the method parameter cannot be blank when calling dispatchaction. If it is null, dispatchaction calls the unspecified method and throws an exception.