Comparison of Spring MVC and STRUTS2

Source: Internet
Author: User

A few days ago, why did we use Spring MVC? What is the root cause of Spring MVC's popularity? is Spring MVC just a convenience in dealing with Ajax requests, and does it have any other advantages?

In response to these questions, I looked up some information from the Internet, comparing the pros and cons of spring MVC and STRUTS2:

1, the core controller (front controller, pre-processing controller): For people who have used the MVC framework, the word should not be unfamiliar, the main purpose of the core controller is to process all requests, and then the special request (Controller) for uniform processing (character encoding, file upload, parameter acceptance, exception handling, etc.) , the SPRINGMVC core controller is a servlet, and Struts2 is the Filter.

2, Learning Difficulty: Struts more new technology points, such as interceptors, value stacks and OGNL expression, learning Cost is higher, SPRINGMVC is relatively simple, very little time can be started.

3, Management mode: Most of the company's core structure, will use to spring, and Springmvc is a module in spring, so spring for the SPRINGMVC controller management more simple and convenient, and provide a full annotated way to manage, Annotations for various functions are comprehensive, simple to use, and struts2 need to be managed with a lot of XML configuration parameters (although annotations can be used, but few companies do).

4, Performance: SPRINGMVC will be slightly faster than Struts2. Springmvc is a method-based design, and Sturts2 is class-based, each time a request is made to instantiate an action, each action is injected into a property, and Springmvc is based on a method, finer granularity, but be careful to control the data like in the servlet. Springmvc is a method-level intercept that, after intercepting the method, injects the request data into the parameter according to the annotations on the parameters, and in Springmvc, a method corresponds to a request context. The STRUTS2 framework is a class-level intercept, creating an action every time a request is made, and then invoking the setter getter method to inject the data from the request; Struts2 actually deals with the request through the setter getter method. ; in Struts2, an Action object corresponds to a request context.

5, Parameter transmission: STRUTS2 in itself to provide a variety of parameters to accept, in fact, are passed through (valuestack) and assigned value, and SPRINGMVC is through the parameters of the method to receive.

6, Design thinking: Struts2 more in line with OOP programming ideas, SPRINGMVC more cautious, extended on the servlet.

7, Intercepter the realization mechanism: STRUTS2 has its own interceptor mechanism, SPRINGMVC uses the independent AOP way. This led to STRUTS2 configuration file volume is still larger than SPRINGMVC, although Struts2 configuration can inherit, so I think on the use of speaking, SPRINGMVC use more concise, development efficiency SPRINGMVC is indeed higher than Struts2. Springmvc is a method-level intercept, a method that corresponds to a request context, and a method that corresponds to a URL, so it is easy to implement a restful URL from the Springmvc of the schema itself. STRUTS2 is class-level interception, a class corresponds to a request context, and implementing a restful URL is laborious because a method of Struts2 action can correspond to a URL, and its class properties are shared by all methods. It is also not possible to identify the method that it belongs to by annotations or other means. The Springmvc method is basically independent, the request response data, requests the data through the parameter acquisition, the processing result passes modelmap to the frame method not to share the variable between, but Struts2 is disorderly, although the method is also independent, But all of its action variables are shared, which does not affect the program's operation, but it gives us code and trouble reading the program.

8, in addition, SPRINGMVC verification is also a bright spot, support JSR303, processing AJAX Requests is more convenient, just a note @responsebody, and then directly return the response text.

9, the use of struts2 when the traditional configuration file method, and did not use the legendary 0 configuration. SPRING3 MVC can be considered already 100% 0 configured (in addition to configuring spring Mvc-servlet.xml)

Comparison of Spring MVC and STRUTS2

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.