Finally, there's a contrast between Springmvc and Struts2.

Source: Internet
Author: User

At present, the proportion of enterprises in the use of SPRINGMVC has far more than Struts2, then what is the difference between the two, is a lot of beginners are more concerned about the problem, the following we will be on the SPRINGMVC and Struts2 in various aspects of the comparison:

1. Core Controller (front controller, pre-processor controller): This word should not be unfamiliar to people who have used the MVC framework, the main purpose of the core controller is to process all requests, and then treat those special requests (controllers) uniformly (character encoding, File uploads, parameter acceptance, exception handling, and so on), the spring MVC Core controller is a servlet, and Struts2 is the filter.

2. Controller instance: Spring MVC will be faster (theoretically) than struts. Spring MVC is based on method design, and Sturts is Object-based, each time a request is made, an action is instantiated, each action is injected into a property, and spring is more like a servlet, with only one instance, Each request executes the corresponding method (note: Because it is a singleton instance, you should avoid modifying the global variables, which can lead to thread safety issues).

3. Management: Most of the company's core architecture will be used to spring, and Spring MVC is a module in spring, so spring for the management of spring MVC is simpler and more convenient, and provides 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. Parameter passing: Struts2 in the self provides a variety of parameters to accept, in fact, are passed through (valuestack) and assignment, and SPRINGMVC is through the parameters of the method to receive.

5. Learning Difficulty: Struts more new technology points, such as interceptors, value stacks and ognl expressions, learning costs are higher, SPRINGMVC is relatively simple, very little time to get started.

6.intercepter implementation mechanism: Struts has its own interceptor mechanism, and spring MVC uses an independent AOP approach. This leads to the profile of struts is still larger than spring MVC, although the configuration of struts can inherit, so I think in terms of use, Spring MVC use more concise, development efficiency Spring MVC is really higher than struts2. Spring MVC 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 spring3 mvc from 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. Spring3 MVC method is basically independent, the request response data, requests data through parameters, processing results through the MODELMAP to the framework method is not shared between the variables, and struts2 make is more chaotic, 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.

7.spring MVC handles AJAX requests directly by returning data, using annotations in methods @responsebody,spring MVC automatically transforms our objects into JSON data.

Finally, there's a contrast between Springmvc 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.