Struts2 Framework Learning (ii) Action
The Action class in the STRUTS2 framework is a separate JavaBean object. Unlike the Struts1 to inherit the httpservlet, the coupling degree is reduced.
1, process
The interceptor intercepts the request, creates the agent Action object, executes the method, returns the result, and the interface jumps.
The interceptor parses the request path, gets the name of the action, finds the full class name of the action in the configuration file , and creates the object with reflection.
Each time a request is made, an object is created, so the action is multi-threaded and thread-safe.
2, relationship
The path of the request and the corresponding relationship of the configuration file:
The namespace value of the package namespace in the configuration file and the name value of the action , such as /user/login plus suffix . Action path, map access the login method in the Loginactin class in the Com.lsz.struts2.action package .
The return string of the method and the result results correspond to the relationship:
The result of the Action class corresponds to the return results in the method , and if there is a return result, configure a result label, and if there are two returns, you need to configure two tags. The name value of the result label is the same as the string returned in the method.
3, method requirements
Must be of type public, and returned as a String, the method is parameterless.
relationship between 4,action class and actionproxy,actioninvocation class
Actionproxy is the proxy class for action, which gets the name and full path in the action class by parsing the configuration file, which is created using the reflection mechanism.
Actioninvocation is the caller of the Action class, and the Actionproxy class created by reflection exists in the Actioninvocaiton class.
Struts2 Framework Learning (ii) Action