In struts2.0, you can get the request object by Servletactioncontext.getrequest ().
return a string in the action's method that corresponds to the name of the result label in Struts.xml, which contains the jump page,
Its principle, as I understand it:
I. The client mentions a (httpservletrequest) request, such as "Http://localhost:8080/TestMvc/add.action" in the browser,
two. The request is submitted to a series (mainly three layers) of the filter (filter), such as Actioncontextcleanup,filterdispatcher
Three. The Filterdispatcher is the core of the controller, Filterdispatcher is initialized and the core dofilter is enabled;
Four. Filterdispatcher asks if Actionmapper needs to invoke an action to process the request, and if Actionmapper decides that an action needs to be called, Filterdispatcher the processing of the request to actionproxy
v. actionproxy through (Struts.xml) asks the framework's configuration file to find the action class that needs to be called.
Vi. Actionproxy creates an instance of Actioninvocation while Actioninvocation invokes the action through proxy mode. But before the call, Actioninvocation will load all interceptor (interceptors) associated with the action based on the configuration the
Actioninvocation works:
1. When Actioninvocation is initialized, all interceptor associated with the action are loaded according to the configuration.
2. When the action implementation is invoked by the Actioninvocation.invoke method, the interceptor is executed.
3. Once the action is executed, Actioninvocation is responsible for finding the corresponding return result based on the configuration in Struts.xml
It can be said that the essence of Struts2 or a servlet (in the S1 for overall control is a filter in a servlet;s2, in fact, it can also be seen as a servlet), just a further encapsulation of the servlet
To make a Web project is like building a house. The servlet is like wood, with a root of the wood, but also can build a house, but the speed is only slow;
And Struts2 is like a house with wood to do a general structure, to build a house, just take it over, and then to its inside the building blocks, tinkering, can quickly build a house, which is much faster than using the servlet directly
Specific comparison
1. Development time. The contrast is that struts is lower than the servlet. Because struts has some configuration files, if some do not pay attention to think, the chance of error is larger than the servlet, rather than using jsp+servlet development at random.
2. Specification of the code. Because Jsp+servlet development is arbitrary. Normative should be poor. Control statements are everywhere, which is inconvenient for maintenance and modification. It also makes it inconvenient for the man to interpret the code.
3. Security. The least secure Web development is the use of the session. Servlet development is inseparable from the request. With the request, that also has a session, before we have a group development, chaos with the session, so that the performance of the system is very. And there's a lot of confidential information leaking out. If you encapsulate the request in Serlet, you'll find it more and more like struts. The values of struts are stored in the Actionform, so a simple encapsulation can make the bottom person, see Requet, do not affect the value.
4. maintainability. This is basically in the late stages of the project, and the comparison is that struts is far better than Servlets. Only in PM control is good. Then the code layering for the struts project is clear. Data layer, page representation, page control, business processing, all of these will be good modules. This has brought a lot of convenience to the later maintenance. Because later, no one wants to introduce a new bug, if using a servlet, the code structure is not clear, very empty easy to introduce new bugs. This is also the most powerful place in struts.
One of the most criticized areas of struts is the early deployment, which is time-consuming to develop. So now the direction is convenient development of easy-borrowing strategy protection framework.
Relationship of Action and servlet