Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What's the difference between SpringMVC and Struts2?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about the difference between SpringMVC and Struts2. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

1. Struts2 is class-level interception, a class corresponds to a request context, SpringMVC is a method-level interception, a method corresponds to a request context, and a method corresponds to a url at the same time, so it is easy to implement restful url from the architecture itself, while the architecture of struts2 is difficult to implement, because a method of Action in Struts2 can correspond to a url, and its class properties are shared by all methods. This makes it impossible to identify the method to which it belongs by annotations or other means.

2. SpringMVC methods are basically independent, exclusive request response data, request data are obtained through parameters, and the processing results are returned to the framework through ModelMap. Variables are not shared between methods, while Struts2 is quite messy. Although the methods are also independent, all its Action variables are shared, which does not affect the running of the program, but brings trouble to us when coding and reading the program. Every time a request comes, we create an Action. An Action object corresponds to a request context.

3. Because Struts2 needs to be encapsulated for each request, encapsulating servlet life cycle variables such as request,session into a Map for each Action to use, and ensuring thread safety, in principle, it is more memory-consuming.

4. In terms of interceptor implementation mechanism, Struts2 has its own interceptor mechanism, and SpringMVC uses an independent AOP mode, so the amount of configuration files of Struts2 is still larger than that of SpringMVC.

5. The entrance to SpringMVC is servlet, while Struts2 is filter. (it should be pointed out here that filter and servlet are different. It was previously thought that filter is a special kind of servlet), which leads to the difference between the two mechanisms, which involves the difference between servlet and filter.

6. SpringMVC integrates Ajax, which is very easy to use. You only need an annotation @ ResponseBody, and then you can return the response text directly. While Struts2 interceptor integrates Ajax, you generally have to install plug-ins or write your own code to integrate them in Action, which is relatively inconvenient to use.

7. SpringMVC verification supports JSR303, which is relatively more flexible and convenient to deal with, while Struts2 verification is tedious and annoying.

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

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

10. The efficiency and performance of SpringMVC is higher than that of Struts2.

11. SpringMVC can be considered as 100% zero configuration.

The above is the difference between SpringMVC and Struts2 shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report