Struts1.1 has been released for so long, I just started systematically learning Struts related knowledge, after the previous median research, there has been further understanding of the class Dispatchaction in Struts1.1. I will summarize here, I hope to help everyone.
In version 1.0 we usually use the Execute method to complete our process and page forwarding of business logic. Usually we can only complete a business logic in an action. If we don't have a way to complete multiple business logics (such as: add, delete, etc.), do we have a way? The answer is negative, we can define a hidden variable in the page, we can give this variable different values when different page requirements are required, and in the Execute method to complete the determination of variable values. Different business logic operations.
For example, we first define a hidden variable on the page.
Then define a JavaScript function, we can modify its value in the function body when you click the Submit button.
Function set (key) {
With (Document.Forms [0]) {
Operat.Value = key;
}
}
Script>
When we click on the Submit button to trigger the event and modify the value of the variable.
Then how do we handle relevant logic in the background execute?
String Operat = myform.getoperat ();
IF (Operat.Equals ("create")) {...
IF (Operat.Equals ("Save")) {...
Very simple! Although this is said that we can implement multiple business logics in the same action, but the price brought is the lengthy and difficult to understand.
Let's take a look at the Dispatchction class. It is a subclass of Action, which can implement the implementation of multiple business logic in the same action, and the above example has become the following form in the dispatchaction:
Public ActionForward Create
ActionMapping mapping,
Actionform Form,
HTTPSERVLETREQUEST REQUEST,
Httpservletresponse response
THROWS EXCEPTION {...
Public ActionForward Save
ActionMapping mapping,
Actionform Form,
HTTPSERVLETREQUEST REQUEST,
Httpservletresponse response
THROWS EXCEPTION {...
Each business logic can find a corresponding method in Dispatchction. So how do we achieve this call? Dispatchaction is slightly troublesome than the general ACTION configuration in Dispatchaction, for example:
Name = "Telform" scope = "request" Validate = "false" parameter = "method" /> We specify the value of parameter for the parameter, and when we ask an action, we must specify the value of Method to determine to go to us. What Action method wants to call. Such as: Http: // localhost: 8080 / TSSS / Telconsle.do? Method = save Obviously, the way we call methods can be achieved by displaying the link to specify the parameter value. However, if we don't want to display call, what should we handle? Remember the method mentioned earlier? We define a hidden variable in the page and then determine our business method we will perform by assigning the value of the variable. Can we use this way so? The answer is yes, we can of course define a variable similar to how about it? By discussion above, can you have a preliminary understanding of DistPatchaction? About Dispatchaction Usage The younger brother is still here, there is any deficiencies, I hope that the prawn can criticize the guidance!