The advantages of Spring MVC and STRUTS2 comparison

Source: Internet
Author: User

We used struts2 when using the traditional configuration file in a way that did not use the legendary 0 configuration. SPRING3 MVC can be thought of as having 100% 0 configured (in addition to configuring spring Mvc-servlet.xml).

The difference between Spring MVC and STRUTS2:

  1. Core Controller (front controller, preprocessing Controller): This word should not be unfamiliar to people who have used the MVC framework, the main purpose of the core controller is to handle all requests, and then handle the special requests (Controller) uniformly (character encoding, file upload, parameter acceptance, exception handling, and so on), the spring MVC Core controller is a servlet, and Struts2 is the filter.

  2. Learning Difficulty: Struts is a lot more new technology points, such as interceptors, value stacks and ognl expressions, high learning costs, springmvc relatively simple, very little time to get started.

  3. Management: in most of the company's core architecture, spring is used, and spring MVC is a module in spring, so spring is simpler and easier for the management of Spring MVC controller, and it provides a full annotated way to manage , the annotations of various functions are more comprehensive and easy to use, while the struts2 need to be managed with many XML configuration parameters (although annotations can be used, but few companies use them).

  4. performance:spring will be slightly faster than struts. Spring MVC is a method-based design, and Sturts is class-based, each time a request is made with an action, each action is injected into the attribute, and spring is based on a method that is finer grained, but be careful to hold the same data as the servlet. SPRING3 MVC is a method-level interception that, after intercepting a method, injects the request data into a parameter based on annotations, and in Spring3 MVC, 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 passing: Struts2 in the self-provided 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.

  6. Design thinking:struts more in line with OOP's programming ideas, spring is more cautious, extended on the servlet.

  7. 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.

  8. < Span style= "Font-family:verdana" > In addition, SPRING3 MVC validation is also a bright spot, support JSR303, processing AJAX Requests is more convenient, just one annotation @responsebody, and then directly return the response text. Send a piece of code:

     @RequestMapping (value= "/whitelists") public String Index (Modelmap map) {Account account = Acco    Untmanager.getbydigitid (Securitycontextholder.get (). Getdigitid ());    List grouplist = Groupmanager.findallgroup (Account.getid ());    Map.put ("account", account);    Map.put ("Grouplist", grouplist); return "/group/group-index";} 
    //@ResponseBody Ajax response, it is also convenient to handle AJAX requests @requestmapping (value= "/whitelist/{whitelistid }/del ") @ResponseBodypublic String Delete (@PathVariable Integer whitelistid) {whitelistmanager.deletewhitelist (    Whitelistid); Return "Success";} 


Advantages of the comparison between 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.