Differences between control layer SpringMVC and Struts2

Source: Internet
Author: User

Differences between control layer SpringMVC and Struts2

We are now using the common MVC layer. The Controller layer of the control layer mainly consists of two frameworks: Struts2 and SpringMVC, which correspond to Action and Controller respectively. So what are the main differences between SpringMVC and Struts?

I. Framework mechanism

We know that Struts2 uses Filter, while SpringMVC uses Servlet.

Struts2 uses StrutsPrepareAndExecuteFilter, while SpringMVC uses DispatcherServlet. Filter is a special Servlet. The Filter is initialized after the container is started, and crashed after the service is stopped, later than the Servlet. The Servlet is initialized during the call and called before the Filter; the service crashes after it is stopped.

 

Ii. Interception Mechanism

1. Struts2

The Struts2 framework is a Class-level interception. Each request creates an Action. During integration with Spring, the Action Bean injection scope of Struts2 is prototype (otherwise thread concurrency problems may occur ), then, use setter and getter to inject request data to attributes.

In Struts2, an Action corresponds to a request and response context. When receiving parameters, the request can be received through attributes. This indicates that the attribute parameters allow multiple methods to be shared.

 

2. SpringMVC

SpringMVC is a method-level interception. A method corresponds to a Request context, so the method is basically independent and exclusive to request and response data. The url corresponding to each method at the same time, the parameter transmission is directly injected into the method, which is unique to the method. The processing result is returned to the framework through ModeMap.

During Spring integration, SpringMVC's Controller Bean adopts Singleton by default in Singleton mode. Therefore, by default, only one Controller is created for all requests, which should be non-shared, therefore, it is thread-safe. To change the default Scope, add the @ Scope annotation and modify it.

 

Iii. Performance

SpringMVC implements Zero Configuration. As SpringMVC intercepts methods, it loads a singleton mode bean injection. Struts2 is a Class-level interception. Each request corresponds to a new Action of the instance, and all attribute values need to be loaded for injection. Therefore, SpringMVC is faster than Struts2.

 

Iv. Interception Mechanism

Struts2 has its own Interceptor mechanism. SpringMVC uses an independent Aop method.

.

 

 

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.