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-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article will explain in detail what is the difference between springMVC and struts2. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

The difference between Spring MVC and Struts2:

1. Mechanism:

The entry to spring mvc is servlet, while struts2 is filter. (to point out here, 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.

two。 Performance:

Spring will be slightly faster than struts. Spring mvc is designed based on methods, while sturts is based on classes. Each request will instantiate an action, and each action will be injected with attributes.

Spring, on the other hand, is method-based and has finer granularity, but you have to be careful with it as you control data in servlet. Spring3 mvc is a method-level interception that injects request data into the method according to the comments on the parameters. In spring3 mvc, a method corresponds to a request context.

The struts2 framework is class-level interception, creating an Action every time a request comes, and then calling the setter getter method to inject the data in the request; struts2 actually deals with request through the setter getter method; in struts2, an Action object corresponds to a request context.

3. Parameter passing:

When struts accepts parameters, you can use attributes to accept parameters, which means that parameters are shared by multiple methods.

4. In terms of design ideas:

Struts is more in line with the programming ideas of oop, while spring is more cautious and extends on servlet.

5. The implementation mechanism of intercepter:

Struts has its own interceptor mechanism, and spring mvc uses an independent AOP approach. As a result, the number of configuration files of struts is still larger than that of spring mvc, although the configuration of struts can be inherited, so I think spring mvc is more concise in terms of use, and Spring MVC is indeed more efficient than struts2.

Spring mvc is method-level interception, a method corresponds to a request context, and a method corresponds to a url at the same time, so spring3 mvc is easy to implement restful url from the architecture itself.

Struts2 is a class-level interception, and a class corresponds to a request context; implementing restful url is laborious, because a method of struts2 action can correspond to a url; and its class properties are shared by all methods, so it is impossible to identify the method it belongs to by annotations or other means.

Spring3 mvc methods are basically independent, exclusive request response data, request data to be obtained through parameters, processing results returned to the framework methods through ModelMap do not share variables, and struts2 is quite messy, although the methods are also independent, but 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.

6. In addition, the verification of spring3 mvc is also a bright spot. It supports JSR303, and it is more convenient to handle the request for ajax. You only need an annotation @ ResponseBody, and then return the response text directly.

About what the difference between springMVC and struts2 is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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

Internet Technology

Wechat

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

12
Report