Strut2 Process Analysis-from request to action method ()
First, the request will call the dofilter () method of strutsprepareandexcutefliter ---- (this is the interceptor we configured in the web. xml file. All action requests must pass this interceptor ).
Then, the system calls the excute () method of the strutsactionproxy class to generate an actionproxy class)
Actionproxy is a proxy class of action. That is to say, action calling is implemented through actionproxy, that is, the defined action cannot directly access various interceptor stacks, we have to find an agent to do this job for us.
This method calls the actioninvocation. Invoke () method.
Then call the invoactionactioninvocation invoke () // call all the interceptors through the continuous callback method until the call is complete.
Actioninvocation is the caller of action.
Actioninvocation schedules a series of elements such as interceptor, action, and result during action execution.
*/
Public String invoke () throws exception {
String profilekey = "INVOKE :";
Try {
Utiltimerstack. Push (profilekey );
If (executed ){
Throw new illegalstateexception ("action has already executed ");
}
If (interceptors. hasnext () {// interceptor set, continuous callback,
Final interceptormapping interceptor = interceptors. Next ();
String interceptormsg = "Interceptor:" + Interceptor. getname ();
Utiltimerstack. Push (interceptormsg );
Try {
Resultcode = Interceptor. getinterceptor (). Intercept (defaactionactioninvocation. This );
}
Finally {
Utiltimerstack. Pop (interceptormsg); // After the interceptor callback is complete, call the action class method through this method.
}
} Else {
Resultcode = invokeactiononly ();
}
1action request process:
Every time an action request occurs, it is not to jump to the corresponding action immediately, but to form an action instance,
Put all the attributes of the Action instance to the top of the stack. At this time, the attributes of the Action object placed in the value Stack are still not assigned a value,
Continue to generate an actionproxy instance, And the actionproxy calls all the interceptors until the parameters interceptor is called to map form fields to the attributes of the top object of the valuestack stack.
Then, when the method corresponding to the action is executed, assign values to each attribute of the action class.
2action class objects are instantiated in the Controller and automatically assigned values using the ognl method.
1) Declare the action class objects to be used
2) Implement the modeldriver interface, implement the GetModel method, instantiate the action class object in the GetModel method, and return the instantiated object (PS: new action () object cannot be directly returned)
Action Request Process Analysis