The difference between struts2 and spring MVC in Java _ Power node of Java College collation

  • 2020-10-23 20:06:37
  • OfStack

1, the interception, Struts2 is class level 1 class 1 request context, SpringMVC is the intercept method level, 1 method corresponding to 1 request context, and the method with a url corresponding again at the same time, from the architecture itself so SpringMVC is easy to implement restful url, and struts2 architecture to implement to struggle, because the Struts2 Action 1 method can correspond to 1 url, while its class attribute method Shared by all, it won't be able to use annotations or other way identify its methods.

2. SpringMVC methods are basically independent of each other and enjoy request response data exclusively. The request data is obtained through parameters, and the processing results are delivered back to the framework through ModelMap, without sharing variables between methods.

3. As Struts2 needs to encapsulate each request, encapsulate the variables of request, session and other servlet life cycle into one Map for each Action to use, and ensure thread safety, it is relatively memory consuming in principle.

4. As for the implementation mechanism of the interceptor, Struts2 has its own interceptor mechanism, while SpringMVC USES the independent AOP mode, which leads to the larger amount of configuration files of Struts2 than SpringMVC.

5. The entrance to SpringMVC is servlet and Struts2 is filter (it should be noted here that filter and servlet are different. Previously, filter was considered as a special type of servlet. This leads to the difference in the mechanism between servlet and filter.

6. SpringMVC integrates Ajax, which is very convenient to use. It only needs one annotation @ResponseBody to realize and then directly return the response text, while Struts2 interceptor integrates Ajax.

7. SpringMVC verification supports JSR303, which is more flexible and convenient to handle, while Struts2 verification is quite complicated, which makes me feel too upset.

8. Spring MVC and Spring are seamless. The management and security of this project is also higher than Struts2 (of course Struts2 can also achieve the effect of SpringMVC1 through different directory structures and related configuration, but there are many places where xml configuration is needed).

9. In terms of design ideas, Struts2 is more in line with the programming ideas of OOP, while SpringMVC is more cautious and expands on servlet.

10. Performance of SpringMVC is higher than that of Struts2.

11. SpringMVC can be considered to have 100% zero configuration.

conclusion


Related articles: