Difference Struts2 framework and the framework of SpringMvc

First, the different mechanisms of interception

  Struts2 is a class-level interceptors, each request will create a Action, Struts2 and Spring integration of ActionBean when injected scope is prototype model prototype, and then injected into the property by setter, getter now request data. Struts2, one Action corresponding to a request, response context, upon receiving the parameters, attributes can be received, which is to be described attribute parameter shared by multiple methods. A method Struts2 in Action may correspond to a url, and it was all methods share class attribute, it will not be able to identify their respective method with annotations or otherwise, can only be designed to be more cases.

  SpringMVC a method of intercepting level, a method corresponding to a context Request, the direct method is substantially independent exclusive request, response data. How can a method of simultaneously and each corresponding to url, transmission parameters are injected directly into the process, the method is unique. Return the processing result to the frame by a ModeMap. When Spring integration, SpringMVC the Controller Bean default Singleton Singleton, so the default for all requests, only to create a Controller, there should be no sharing of property, it is thread-safe, if you want to change the default scope, @Scope need to add annotations to modify.

  Struts2 interceptor Interceptor has its own mechanisms, SpringMVC which is a separate Aop way, this has led to the configuration file is larger than the amount of Struts2 SpringMVC.

Second, different underlying framework

  Struts2 using Filter (StrutsPrepareAndExecuteFilter) implemented, SpringMVC (DispatcherServlet) Servlet implementation is used. Filter is initialization after the vessel started; service is stopped after the crash, later than Servlet. In the Servlet is initialized when you call, the first call to Filter, the service stops destroyed.

Third, performance

  S truts2 intercept a class level, corresponding to each request a new instance of the Action, need to load all attribute values injection, SpringMVC achieve zero-configuration, since the method is based SpringMVC interception with a single loading mode embodiment bean injection. So, SpringMVC development efficiency and performance than Struts2.

Fourth, the configuration

  spring MVC and Spring is seamless. Too high from the management and security of this project than Struts2 .

 

Note: The difference between the interceptor and filter  :

 

  1. Interceptor java reflection mechanism is based, and the filter is based on a callback function.
  2. Interceptor does not rely servlet container, and the filter dependent servlet container.
  3. Action can only request interceptor function, and the filter can act on almost all the requests.
  4. Action interceptors can access context, the value of the stack of objects, and the filter can not be accessed.
  5. In the action of the life cycle, the interceptor can be called multiple times, and the filter can only be called once when the container is initialized

Guess you like

Origin www.cnblogs.com/chx9832/p/11601394.html