Struts process Struts Controller Basic Function is 1. Intercepting the user's HTTP request 2. Map the request to a defined business operation 3. Get the business operation result, provide to the client 4. Which page should be displayed next? There are several parts to form a struts' Controller. The user's request is sent to the ActionServlet, and the ActionServlet calls the processprossor to start processing the process of user request. In this process, the ApplicationConfig will be found, and the Action corresponding to the user request, call the corresponding action Specifically perform the user's request, finally return ActionForward, turn to the corresponding process. ================ org.apache.struts.Action.ActionServlet is the most important part of Struts Controller, all user requests are sent here, all other processing must also be Here. ActionServlet is inherited from httpservlet. When the ActionServlet receives HTTP Request, the process () method is called regardless of the doget () or dopost () method. protected void process (HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {RequestUtils.selectApplication (request, getServletContext ()); getApplicationConfig (request) .getProcessor () process (request, response);.} In general, we do not need Implement or modify the ActionServlet class, just use it. In some cases, we can extend your ActionServlet class, inherit from ActionServlet, and implement your own MyActionServlet class. Some of the methods covered to achieve your special treatment. ActionServlet inherits from Javax.Servlet.http.httpservlet, so it doesn't matter in nature it and a normal servlet, you can look at it as a servlet, just in which the function is complete. ================/ Requestprossor handles the user's Request, as a request handler exists. Similarly, when processed Request, the Process (Execute) method in the RequestProcessor class is executed. The method of calling in Process is overloaded, if necessary, can be implemented as a specific method. For example, for Locale issues, it is usually read when the system is loaded. If the user wants to switch or select your own locale at any time, we can overload the ProcessLocale () method.
You can then only need to add the segment in the configuration file ================ Action class is the core part of the entire system, which is between customer requests, interface representations and business logic Play to a bridge. Each Action is used to handle a task, or make a business operation. Of course, we say a task is not to say that Action only implements a business operation method, but a set of functional units. For example, logon's logonAction, search for Searchaction, and more. Action is in RequestProcessor, a very important point called by ProcessActionPerform method: Do not include any business logic operation in the Action, but should call a MODEL layer JavaBean to implement your business logic. In some cases, a small performance logic may be included. In this way, you can fully perform code reuse, such as the IStoreFrontService interface called in the previous example, which can be used without considering the client, so it can be used by other or other systems. Otherwise, Action will become very difficult to understand, it is difficult to maintain, and the code cannot be reused. The Struts-Example engineering design is a bug that encapsulates business logic to the action class =================== In the action of an action, return an ActionForward class. ActionForward packages the information of the Forward section in the configuration file to reduce the coupling between the application and physical resource information. With the ActionMApping class, you can find the corresponding Forward information in the configuration file. For example, for a loginaction, its configuration information may be like this: The returned ActionForward will contain information in the segment. In the FindForward method of the ActionMapping class, you will first find the corresponding Forward segment according to the findings forward, if not, you will find a lookup in the configuration file, if you have not yet throw an exception. ===================== In the page, the input data on the page is submitted by HTTP REQUEST, the service party retrieves the input data, verifies, and passes these data. Give other components to business processing. Everything is basically needed to write code to operate, more troublesome, and make the code complicated. Actionform [org.apache.struts.Action.Actionform] is used to collect users' input and pass this information to the Action object, and then in the Action object, the data in the ActionForm is taken out to the service logic layer. On one hand, as a buffer, temporary storage of data input data; on the other hand, the actionform is a firewall between http and action, which can verify the correctness of the input data, if the verification is not passed, this request is Will not be sent to the Action for processing.