Comparison between Struts and Spring MVC frameworks

Source: Internet
Author: User

Web-based MVC framework has become an unprecedented boom in the world of J2EE. The TTS website has released a new MVC Framework almost every one or two weeks. Currently, MVC is better, and old ones include Struts and Webwork. Emerging MVC frameworks include Spring MVC, Tapestry, and JSF. Most of these are works of famous teams, and there are also some excellent works of edge teams, such as Dinamica and VRaptor. These frameworks provide good hierarchical separation capabilities. Based on the implementation of good MVC separation, by providing some ready-made auxiliary class libraries, it also promotes the improvement of production efficiency.

Selecting a good framework application in your project is crucial to the efficiency and reusability of your project. This article will introduce the two most popular and commonly used frameworks.

I. Struts

Struts is part of the Jakarta project under the Apache Software Foundation. The main Architecture Design and developer of the Struts framework is Craig R. McClanahan. Struts is currently an indisputable leader in the Java Web MVC framework. After five years of development, Struts has gradually grown into a stable and mature framework, and occupies the largest market share of the MVC framework. However, Struts lags behind the emerging MVC framework in some technical features. Struts is facing unprecedented challenges in the face of more sophisticated and scalable frameworks such as Spring MVC and Webwork2. However, from the perspective of product development, Struts is still the safest choice.

Struts consists of a group of collaborative classes (components), Serlvet, and jsp tag lib. Web applications based on the struts architecture basically comply with the design standards of JSP Model2, and can be said to be a type of change in the MVC design pattern. According to the above descriptions of the framework, we can easily understand why Struts is a web framwork, not just a combination of some tag libraries. However, Struts also contains a wide range of tag libraries and Utility Classes that work independently of the framework. Struts has its own Controller and integrates other technologies to implement Model and View ). In the model layer, Struts can easily be combined with data access technologies, including EJB, JDBC, and Object Relation Bridge. In the view layer, Struts can be combined with JSP, Velocity Templates, XSL, and other presentation layer components.

Struts Architecture

Struts framework is the embodiment of the MVC model. Next we will look at the struts Architecture from the perspectives of model, view, and control ).

View)

It is mainly created by JSP. struts itself contains a set of scalable custom tag libraries (TagLib), which can simplify the process of creating user interfaces. Currently, Taglib includes Bean Tags, HTML Tags, Logic Tags, Nested Tags, and Template Tags. For more information, see the struts user manual.

Model)

The model mainly represents the state of a system (sometimes, the business logic operations that change the state of the system are also divided into the model ). In Struts, the status of the system is mainly embodied in ActiomForm Bean. In general, these statuses are non-persistent. To convert these statuses to persistent data storage, Struts also provides the Utitle package to facilitate database operations.

Controller)

In Struts framework, the Controller is mainly ActionServlet, but the operations on the business logic are mainly coordinated by the Action, ActionMapping, and ActionForward components (maybe these components, should be divided into the business logic in the model ). Action acts as the real implementer of the business logic, while ActionMapping and ActionForward specify the operation direction of different business logic or processes.
For how Struts controls and processes customer requests, let's introduce the four core components of struts. These components are: ActionServlet. Action Classes, Action Mapping (including ActionForward), and Action from Bean.

Ii. Spring

Spring is actually the concrete implementation of the Design idea described in the book "Expert One-on-One J2EE Design and Development. In One-on-One, Rod Johnson advocates the design idea of J2EE pragmatism and provides a preliminary development framework implementation (interface21 Development Kit ). Spring is a more comprehensive and concrete embodiment of this idea. Based on the interface21 Development Kit, Rod Johnson further transformed and expanded it to become a more open, clear, comprehensive, and efficient development framework.

Spring is an open-source framework created by Rod Johnson and described in his book J2EE design and development programming guide. It is created to solve the complexity of enterprise application development. Spring makes it possible to use the basic JavaBeans to accomplish the tasks previously only completed by EJB. However, Spring is not only used for server-side development. From the perspective of simplicity, testability, and loose coupling, any Java application can benefit from Spring.

In simple terms, Spring is a lightweight container framework that controls inversion and face-to-face. Of course, this description is too simple. But it does summarize what Spring does. To better understand Spring, let's analyze this description:

1. Lightweight. Spring is lightweight in terms of size and overhead. The complete Spring framework can be published in a JAR file with a size of more than 1 MB. In addition, the processing overhead required by Spring is negligible. In addition, Spring is non-intrusive: Typically, objects in Spring applications do not depend on lightweight objects ?? Spring is lightweight in terms of size and overhead. The complete Spring framework can be published in a JAR file with a size of more than 1 MB. In addition, the processing overhead required by Spring is negligible. In addition, Spring is non-intrusive: Typically, objects in Spring applications do not depend on specific classes of Spring.

2. Control reversal ?? Spring promotes loose coupling through a technology called IoC. When IoC is applied, objects passively pass their dependencies instead of creating or searching for dependent objects by themselves. Do you think IoC is the opposite of JNDI ?? Instead of looking for Dependencies from the container, the container passes dependencies to the object before it is requested during object initialization.

3. Face-oriented question mark ?? Spring provides rich support for Aspect-Oriented Programming and allows the development of cohesion by separating application business logic and system services (such as audit and transaction management. What do application objects only do ?? Complete business logic ?? That's all. They are not responsible (or even conscious) for other system concerns, such as log or transaction support.

4. Container ?? Spring contains and manages the configuration and lifecycle of application objects. In this sense, Spring is a container. You can configure how each of your beans is created ?? Create a separate instance for your bean based on a configuration prototype or generate a new instance every time you need it ?? And how they are associated. However, Spring should not be mixed with traditional heavy EJB containers, which are often large and bulky and difficult to use.

Framework: Spring makes it possible to configure and combine complex applications by simple components. In Spring, application objects are declared and combined, typically in an XML file. Spring also provides many basic functions (such as transaction management and persistent framework integration), leaving the development of application logic to you.

All of these features of Spring allow you to write code that is cleaner, manageable, and easier to test. They also provide the basis for various seed frameworks in Spring.

Related Article

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.