1. Let's introduce the workflow of the Struts controller first. First, the controller (ActionServlet) performs an initialization, read configuration file struts-config.xml, initializes the corresponding moduleconfig object for different Struts modules. There is a ControlConfig collection, a FormBeanconfig collection, a ForwardConfig collection, and a MessageResourcesConfig collection. A subclass of inherited ActionServlets is designed in AppFuse: loginservlets are used as a controller to extension the functionality of the ActionServlet. The main function is to initialize some of the components used in this system, such as the security check URL of the user's identity, password encryption rules, etc. The controller receives the HTTP request and identifies the Action subclass corresponding to the request from ActionConfig. If there is no corresponding action, the controller directly forwards the request to the JSP or static page. Otherwise, the controller distributes the request to the specific Action class for processing. Before the controller calls the specific Action method, the corresponding ACTIONFORM object will use the parameters in the HTTP request to populate yourself. In addition, if the ACTIONForm class is configured, the Validate component is called to check the legality of the request parameter and return a ActionerRors object containing all error messages. If the execution is successful, the ActionForm automatically saves these parameter information in the formBean manner, so they can be called by other Action objects or JSP. After performing the method in completing the action, return an ActionForward object, and the controller is forwarded by the ActionForward object.
The most important functionality implemented by the AppFuse is to manage the user. The following is to illustrate the implementation of the AppFUSE controller to manage the user.
The FORMBEAN related to user information form data is Userform. Userform is used to store basic information about the user. Userform's controller is Org.Appfuse.Webapp.action.Useraction. UserAction inherited the baseAction. BaseAction is also a parent class of almost all Action classes in the system, which inherits the Dispatchction provided from Struts, and provides a method of controlling the control layer.
2. ActionAction is a bridge between user requests and business logic, each Action acting as a business agent of a customer. Mainly complete the following tasks: 1. Receive user requests. 2. According to the user request, call the appropriate model component to perform the corresponding business logic. 3. Get business logic execution results 4. Select the appropriate view component to return to the user based on the current status and the result of the business logic.
3. Dispatchaction org.apache.struts.Actions.dispatchaction is the subclass of org.apache.struts.Action.Action. The action's execute () method is to call the business method of the model, complete the service logic requested by the user, and then forward the request to other suitable web components based on the execution result. Typically, only one business operation can be completed in an Action class (by the execute () method). Dispatchaction allows users to set the continuous action and related action required for a business logic to focus in an Action class. There is no need to override the Execute () method, but can create a method of implementing the actual business operation, and the user specifies the method you need to use by the Method request parameter.
4. BaseAction BaseAction implements the general method of the Action subclass in the system, mainly: 1. Public Object getBean (String Name): Create an instance by reading the spring ApplicationContext-Service.xml configuration file Dependent the method of injection. 2. Public ActionMessages getMessages (httpservletRequest request): Initialize Struts's actionMessages and returns. 3. Protected Object Convert (Object O): The conversion method between POJO and FORMBEAN. 4. Execute (): Replace the original Execute () method. The role is to find a related business method according to the requested URL (when there is no Method request parameter). For example, the requested page is edituser.html, execute the Edit () method. 5. Protected actionform getActionform (ActionMApping mapping, httpservletRequest Request): Get an Action FormBean within the mapping range. 6. Protected User GetUser (HTTPSESSION session): Takes the current login user information from the session. 7. Protected Void UpdateFormBean (ActionMapping Mapping, HttpServletRequest Request, ActionForm Form): Update the FORM Bean object corresponding to the current Action within the specified range. 8. Protected Void RemoveFormBean (ActionMApping Mapping, HttpServletRequest Request): Remove the useless Form Bean.