How to Struts Dispatchaction Submit on the form with Method parameters

xiaoxiao2021-03-06  43

Dispatchaction is another Action class that Struts that can save a large amount of saving time. I want to use Dispatchction to make a function of adding, modifying, deleting records from forms.

ADD, Alert, delete, etc. in MyDispatchaction, how is the number of parameters when adding a form?

For example: Press the Add Button to implement myDispathaction? Method = add this to a submission?

1. Use dispatchaction

Dispatchaction is another Action class that Struts contains a large amount of saving time. Unlike other Action classes, only a single execute () method implements a single business, and DispatchAction allows you to write multiple methods related to your business in a single Action class. This reduces the number of Action classes and collects the relevant business methods to make maintenance easier.

To use Dispatchaction's features, you need to create a class yourself and get it by inheriting abstract dispatchaction. There must be a specific method Signature for each business method to provide. For example, we want to provide a method to implement a list of goods to the shopping cart, create a class ShoppingCartDispatchaction provides the following methods:

Then, this class is likely to need a deleteItem () method to remove a list of items from the customer's shopping cart, and the ClearCart () method clears the shopping cart and so on. At this time we can set these methods in a single Action class, without providing an Action class for each method.

When you call a method in the ShopPingCartDispatchaction, just provide the method name as the parameter value in the URL. That is to say, call addItem () Fang ǖ? URL looks like:

http: // myhost / storefront / action / cart? method = additem

The Method parameter specifies the method to be called in the ShoppingCartDispatchaction. The name of the parameter can be arbitrarily configured, "Method" used here is just an example. The name of the parameter can be set in the STRUTS configuration file.

2. Using LookUpdispatchaction

Org.apache.struts.Actions.lookupdispatchaction class:

Usually lookupdispatchaction is primarily applied to multiple submission buttons in a form, and these buttons have a common name, the names of these buttons, and the specific actionMApping parameter properties.

When configuring lookupdispatchaction, you should set the parameter property to "action" in the element, which is consistent with the Property property of the tag.

Be a hidden variable.

Then use JS to judge