Learning to use dispatchaction

Source: Internet
Author: User

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.

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.