The difference between SPRINGMVC and Struts2
I. Framework mechanism
1, Struts2 adopts filter (Strutsprepareandexecutefilter) implementation, SPRINGMVC (Dispatcherservlet) is implemented by servlet.
2, the filter is initialized after the container is started; The service stopped and crashed later than the servlet. The servlet is initialized at invocation, prior to the filter call, and destroyed after the service is stopped.
This involves the difference between a servlet and a filter.
Second, interception mechanism
1, Struts2
A, STRUTS2 framework is class-level interception, each request will create an action, and spring consolidation when the Struts2 Actionbean injection scope is the prototype mode prototype (otherwise there will be thread concurrency problems), Then inject the data into the properties via the Setter,getter bar request.
B, in Struts2, an action corresponds to a request,response context, which can be received via a property when the parameter is received, which means that the attribute parameter is shared by multiple methods.
C, a method of action in Struts2 can correspond to a URL, and its class properties are shared by all methods, it is not possible to use annotations or other ways to identify the method they belong to
2, Springmvc
A, Springmvc is a method-level interception, a method corresponding to a request context, so the method is directly basically independent, exclusive access to request,response data. And each method at the same time what a URL corresponding, parameter transfer is directly injected into the method, is unique to the method. The processing results are returned to the framework by Modemap.
B, in the spring integration, SPRINGMVC controller bean default singleton mode singleton, so the default for all requests, will only create a controller, there should be no shared properties, so it is thread-safe, If you want to change the default scope, you need to add @scope annotation modifications.
third, performance aspects
1, SPRINGMVC Implementation of the 0 configuration, due to SPRINGMVC based on the method of interception, there is a single sample mode bean injection. While Struts2 is a class-level intercept, each time a new action is requested for the corresponding instance, all attribute value injections need to be loaded, so SPRINGMVC development efficiency and performance is higher than Struts2.
2, spring will be slightly faster than struts. Spring MVC is a method-based design, and Sturts is class-based, each time a request is made with an action, each action is injected into the attribute, and spring is based on a method that is finer grained, but be careful to hold the same data as the servlet. SPRING3 MVC is a method-level interception that, after intercepting a method, injects the request data into a parameter based on annotations, and in Spring3 MVC, a method corresponds to a request context. The STRUTS2 framework is class-level blocking, creating an action each time a request is made, and then invoking the setter getter method to inject the data from the request; Struts2 is actually a pass setter getter method that deals with the request. ; in Struts2, an Action object corresponds to a request context.
The above two say one can!
Iv. interception mechanism
STRUTS2 has its own interception interceptor mechanism, SPRINGMVC This is a separate AOP approach, which results in STRUTS2 configuration file volume is larger than SPRINGMVC.
V. Configuration aspects
Spring MVC and Spring are seamless. From this project management and security is also higher than Struts2 (of course Struts2 can also be done through different directory structure and related configuration to achieve springmvc the same effect, but need XML configuration of a lot of places).
SPRINGMVC can be considered already 100% 0 configured.
VI. Design ideas
Struts2 more in line with OOP's programming ideas, SPRINGMVC is more cautious and expands on the servlet.
Vii. Integration aspects
SPRINGMVC integrates Ajax, is very convenient to use, just one annotation @responsebody can be implemented, and then directly return to the response text, and STRUTS2 interceptor integrated Ajax, In action, it is generally necessary to install plug-ins or write code to integrate them, it is relatively inconvenient to use.
Eight, the realization mechanism of intercepter
STRUTS2 has its own interceptor mechanism, and spring MVC uses an independent AOP approach. This leads to the profile of struts is still larger than spring MVC, although the configuration of struts can inherit, so I think in terms of use, Spring MVC use more concise, development efficiency Spring MVC is really higher than struts2. Spring MVC is a method-level intercept, a method that corresponds to a request context, and a method that corresponds to a URL, so it is easy to implement a restful URL spring3 mvc from the schema itself. STRUTS2 is class-level interception, a class corresponds to a request context, and implementing a restful URL is laborious because a method of struts2 action can correspond to a URL, and its class properties are shared by all methods. It is also not possible to identify the method that it belongs to by annotations or other means. Spring3 MVC method is basically independent, the request response data, requests data through parameters, processing results through the MODELMAP to the framework method is not shared between the variables, and struts2 make is more chaotic, although the method is also independent, But all of its action variables are shared, which does not affect the program's operation, but it gives us code and trouble reading the program.
The difference between SPRINGMVC and Struts2 in the Java plane question