Struts process

zhaozj2021-02-16  42

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 don't need to 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 deals with the user's request, as an 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. Then just join the segment in the configuration file.

================ Action class is a core part of the entire system, which plays a bridge between customer requests, interface representations, and business logic. 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 project is a bug that encapsulates the business logic to the action class ====================

In an Action's Execute method, 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.

=====================

Previously, the input data on the page passes the HTTP Request Submit, the service party retrieves the input data, verifia, and then passes these data to other components for 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. ActionForm can have two scope, requests, or session. Request is only in Rquest to Response, then ActionForm is not visible; session can save time longer. ==================

The ActionerRors object is returned in the Validate method of ActionForm. This object can encapsulate the error message and automatically display them to the user. Add it on the corresponding JSP page, you can automatically display the error information in ActionerRors. Includes, each particular, an error message added to add, and an ErrorHeader and an ErrorFooter, which can be specified by the configuration file and can contain HTML syntax.

==========================

Struts provides four custom TAG libraries: bean: struts-bean taglib is included in the TAG that is used when accessing the bean and bean properties, and also contains some messages displayed TAG. HTML: Struts-HTML Taglib contains Tags used to create a struts input form, and others are typically used to create TAG based on HTML user interfaces. Logic: Struts-logic taglib contains TAGs to manage information generated according to the condition, and some other information used to control. Template: Struts-Template Taglib is included to define a template mechanism.

转载请注明原文地址:https://www.9cbs.com/read-27460.html

New Post(0)