Comparison of two MVC frameworks for struts and spring

Source: Internet
Author: User
Tags comparison contains html tags java web
Comparison

The web-based MVC framework is an unprecedented boom in the world of Java EE. A new MVC framework is published almost every two weeks on the TTS Web site. At present, the better MVC, the veteran has struts, webwork. The emerging MVC framework is Spring MVC, Tapestry, JSF, and so on. These are mostly the works of the famous team, as well as some of the work of the Fringe team, also quite outstanding, such as Dinamica, Vraptor and so on. These frameworks provide a good level of separation capability. On the basis of a good MVC separation, the provision of some out-of-the-box auxiliary class libraries also facilitates productivity improvement.

How to choose a good framework application in your project will be critical to the efficiency and reusability of your project. This article will introduce the two kinds of framework which are most popular and most commonly used.

First, Struts

Struts is part of the Jakarta Project under the Apache Software Fund. The main architectural design and developer of the Struts framework is Craig R.mcclanahan. Struts is the undisputed king of the current Java WEB MVC framework. After five years of development, struts has grown into a stable, mature framework, and occupies the largest market share in the MVC framework. But some of the technical features of struts have lagged behind the emerging MVC framework. In the face of Spring MVC, WEBWORK2, a more sophisticated and scalable framework, struts has faced unprecedented challenges. But in terms of product development, struts is still the safest option.

Struts consists of a set of mutually collaborative classes (components), Serlvet, and JSP tag lib. The Web application based on struts architecture basically conforms to the design standard of JSP Model2, which can be said to be a kind of change of MVC design pattern. Based on the description of the framework, it is easy to understand why struts is a web framwork, not just a combination of some tag libraries. But Struts also contains a rich tag library and utility classes that work independently of the framework. Struts has its own controller (Controller), while consolidating other technologies to implement the model and view layers. At the model level, struts can be easily 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 so on, these presentation layer components.

The architecture of Struts

The struts framework is the embodiment of the MVC pattern, and here we look at the Struts Architecture (architecture) from the model, view, and control.

From view angle

Built primarily by JSP, struts itself includes a set of extensible custom Tag libraries (TAGLIB) that simplify the process of creating a user interface. Currently includes: Bean tags,html tags,logic tags,nested tags,template Tags these several taglib. For more information, refer to the Struts user manual.

From model angle (mode)

The model mainly represents the state of a system (sometimes, the business logic operation that changes the state of the system is also divided into the model). In struts, the state of the system is mainly represented by actiomform beans, which are typically non-persistent. If you need to convert these states to persistent data storage, struts itself provides a utitle package that can be easily manipulated with the database.

From the controller angle (Controller)

In the struts framework, controller is primarily Actionservlet, but operations on the business logic are mainly performed by action, Actionmapping, Actionforward These components are coordinated (perhaps these components should be divided into the business logic piece in the model). Where the action acts as the real business logic implementation, actionmapping and Actionforward specify the direction of the different business logic or process.

For struts to control and process customer requests, let us specify this by introducing the four core components of struts. These are the following components: Actionservlet. Action classes,action Mapping (here includes Actionforward), Actionfrom Bean.

Second, Spring

Spring is actually a concrete implementation of the design idea elaborated in the book "Expert One-on-one Java and Development". In one-on-one's book, Rod Johnson advocates the design of Java-ee pragmatism, and provides an initial development framework implementation (INTERFACE21 development package) with the book. And spring is the more comprehensive and concrete embodiment of this idea. Rod Johnson on the basis of the INTERFACE21 development package, the further transformation and expansion, so that it developed into a more open, clear, comprehensive and efficient development framework.

Spring is an open source framework that was created by Rod Johnson and described in his book, "Java EE Design and Development Programming Guide." It is created to address the complexity of enterprise application development. Spring makes it possible to use basic javabeans to accomplish things that were previously only possible by EJB. However, the purpose of spring is not limited to server-side development. In terms of simplicity, testability, and loose coupling, any Java application can benefit from spring.

In short, spring is a container framework for lightweight control reversals and facet-oriented containers. Of course, this description is a bit too simple. But it does outline what spring does. To better understand spring, let's analyze This description:

1, Light quantity

Spring is lightweight both in terms of size and cost. The complete spring framework can be published in a jar file that is only 1MB large. and the processing overhead required by spring is negligible. In addition, Spring is non-intrusive: Typically, objects in spring applications do not rely on light weight, and spring is lightweight both in terms of size and cost. The complete spring framework can be published in a jar file that is only 1MB large. and the processing overhead required by spring is negligible. In addition, Spring is non-intrusive: Typically, objects in a spring application do not depend on a particular class of spring.

2, control reversal

Spring promotes loose coupling through a technology called Control reversal (IoC). When IOC is applied, objects passively pass their dependencies instead of creating or locating dependent objects themselves. You can think of IOC as the opposite of Jndi?? Instead of looking for dependencies from the container, the container passes the dependencies to it when the object is initialized without waiting for it to be requested.

3, facing the plane

Spring contains rich support for aspect-oriented programming, allowing for cohesive development through separation of application business logic and system services such as auditing and things management. The application objects only do what they should do, complete the business logic, and that's it. They are not responsible (or even conscious) of other system concerns, such as log or object support.

4. Container

Spring contains and manages the configuration and lifecycle of the Application object, which in this sense is a container. How can you configure how each bean is created? Based on a configuration prototype create a separate instance of your bean or generate a new instance each time you need it and how they relate to each other. However, spring should not be confused with the traditional weights of EJB containers, which are often bulky and unwieldy and difficult to use.

Framework: Spring is made possible by simple component configurations and complex applications. In spring, application objects are declaratively grouped, typically in an XML file. Spring also provides a number of basic functions (transaction management, persistence framework integration, and so on) that leave the development of application logic to you.

All of Spring's features enable you to write cleaner, more manageable, and more testable code. They also provide the basis for various child frameworks in spring.



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.