|
ActionMapping
ActionMapping will classify the effective business logic in the Struts application. When a request arrives, the ActionSevlet looks up the corresponding information in the ActionMapping directory. ActionMapping is a core design of Struts applications. When you need to understand a Struts application or write a new Struts application, you should start with ActionMapping. ActionMapping has more attribute information, please refer to related documents for details.
ActionForward
ActionForward is one of the core classes of Struts, and its base class has only 4 attributes: name / path / redirect / classname. In the development process of Web applications based on Struts, after the Action operation is completed, the program will be linked to the specified ActionForward through the Struts configuration file struts-config.xml, and passed to the core class ActionServlet of Struts. The ActionServlet uses the path provided by ActionForward to control Pass to the next step. ActionForward controls the direction of the next program. ActionForward represents the URI of an application, which includes the path and parameters, for example:
path = "" / modify.do?method=edit&id=10 "
In addition to setting the parameters of ActionForward in struts-config.xml and the page, you can also add parameters in the Action class or recreate an ActionForward in Action.
There is an important attribute redirect in ActionForward. When redirect = false, all the content stored in the http request and request context will be saved and only available in the same application. When redirect = true, the web client makes a new http request, the requested resource can be in the same application or not, the original request parameters are no longer saved, the original request context is also cleared, and the new http request Only include the parameters contained in the path attribute of ActionForward. If in the same application, the context of the user session will be maintained.
ActionForward is divided into global forwarding and local forwarding. The findForward method of Action's Mapping object will first check the local forwarding list, and if it fails to find, it will look in the global forwarding list. In the writing format, we generally define global variables as String constants to avoid misunderstandings and make the forwarding list structure clear and easy to read.
During the project development process, a situation is often encountered. When the page has changed, the address in the browser such as /modify.do or /modify.jsp has not changed. At that time, it was not considered so fine. Although there is doubt, it has no effect To realize the function of the program, so I ignored it. I found some information today to find out. The client browser displays the last URL given to the browser. After the URL is submitted, the web application may have forwarded the request multiple times before a component returns a response to the browser, and these processes all occur on the server. At the end, the client browser does not know what has changed. When an http response is returned, it does not contain the value of the address bar, so the browser only displays the address it used as the initial request. By using redirect, you can change the display of the browser address, because this can submit a new request to the browser, but the price paid is that the data cannot be passed to the page through the request context, which is also one of the differences between using forward and redirect. |
|