Differences Between Spring MVC and struts2

Source: Internet
Author: User

1. mechanism: the entry of spring MVC is servlet, while struts2 is filter, which leads to different mechanisms between them.

2. Performance: Spring is slightly faster than struts. Spring MVC is a method-based design, while sturts is a class-based design. Each request is sent with an action instance, and each action is injected with attributes. Spring is based on methods with finer granularity, but be careful with the data as controlled in servlet. Spring3 MVC is a method-level interception. After the method is intercepted, the request data is injected according to the Annotation on the parameter. In spring3 MVC, a method corresponds to a request context. The struts2 framework is a Class-level interception. Every time a request is sent, an action is created and setter is called.
The getter method injects the data in the request; struts2 actually deals with the request through the setter getter method; In struts2, an action object corresponds to a request context.

3. parameter passing: struts can accept parameters using attributes when accepting parameters. This means that parameters are shared by multiple methods.

4. design ideology: struts is more in line with the OOP programming ideology, so spring is more cautious and can be expanded on servlet.

5. intercepter Implementation Mechanism: struts has its own interceptor mechanism, and spring MVC uses an independent AOP method. As a result, the number of struts configuration files is larger than that of spring MVC. Although struts configurations can be inherited, I think spring MVC is more concise in terms of usage, development efficiency spring MVC is indeed higher than struts2. Spring MVC is a method-level interception. A method corresponds to a request context, and the method corresponds to a URL at the same time. Therefore, spring3 MVC can easily implement restful URLs in the architecture itself. Struts2 is a Class-level interception. A Class corresponds to a request context; implements restful
It is difficult to identify a URL, because a method of struts2 action can correspond to a URL, and its class attributes are shared by all methods, so that the method cannot be identified by annotations or other methods. Spring3 MVC methods are basically independent, with exclusive request response data. The request data is obtained through parameters, and the processing results are returned to framework methods through modelmap without sharing variables, struts2 is messy. Although the methods are independent, all their action variables are shared, which does not affect the program running, but it gives us coding and troubles when reading the program.

6. In addition, spring3 MVC verification is also a highlight. jsr303 is supported. It is more convenient to process Ajax requests. You only need an annotation @ responsebody and then directly return the response text.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.