Struts1, WebWork, Struts2 Introduction

Source: Internet
Author: User

First, Struts1 1. Introduction of Struts1 Principle

The STRUTS1 framework takes Actionservlet as the controller core, and the entire application is driven by client requests. When the client sends a request to the Web app, the request is intercepted by the STRUTS1 core controller actionservlet, Actionservlet on request to decide whether to call the business logic controller to process the user request (in fact, the business logic controller or the controller, It is only responsible for invoking the model to handle user requests, and when the user requests processing is completed, its processing results are presented to the user via JSP.

STRUTS1, the controller is its core, the STRUTS1 controller is divided into the core controller and the business logic controller. The core controller is Actionservlet, provided by the STURTS1 framework, and the business logic control is a user-defined action, provided by the application developer.

Struts1 Running Process:

2. MVC Analysis(1), Model

The model part of the Struts1 is played by the underlying business logic components, which encapsulate the underlying database access and the business logic approach implementation.

(2), View

The view portion of STRUTS1 is implemented using JSP. Not support freemarker, velocity and other template technology, support the performance of a single layer of technology.

(3), Controller

Consists of two parts.

System core Controller: provided by the STRUTS1 framework, is the system's actionservlet.

Business logic controller: provided by the STRUTS1 framework, is the user's own implementation of the action instance.

3. Advantages and Disadvantages

For the STRUTS1 framework, because it is very tightly coupled to the jsp/servlet because it leads to a lot of flaws--------that is why Struts2 occurs.

(1), supporting the presentation layer technology single

Template technologies such as freemarker, velocity, etc. are not supported. The controller does not directly perform a forwarding request, but simply returns a logical view name (Actionforward object)----The actual forwarding is placed in the configuration file.

(2), severe coupling with servlet, difficult to test

For the Execute method that handles the request, it has four parameters, Actionmapping, Actionform, HttpServletRequest, and HttpServletResponse.

(3), the code is heavily dependent on the Struts1 API, is an intrusive design

The design of the action class results in a lower code reuse.

Second, WebWork 1. Introduction of WebWork Principle

From the processing process, it is very similar to the STRUTS1, the core is composed of the controller, and is divided into two parts, the core controller Servletdispatch and the business logic controller action. WebWork uses the OGNL expression language to access the value stack. And based on Xwork, use Servletdispatcher as the core controller to handle HTTP responses and requests. Support for more presentation layer technologies, such as Freemarker and XSLT. Moreover, a more loosely coupled design is used, which makes testing more convenient and allows the system to convert from B/s structure to C/s structure.

The data flow chart is as follows:

2. Advantages

(1), the action does not need to be coupled with the Servlet API, easier to test.

(2), action does not need to be coupled with WebWork, code reuse is high

(3), support more performance layer technology.

Third, Struts2 1. Introduction of STRUTS2 Principle

The STRUTS2 employs a webwork design core, using a large number of interceptors to process user requests, allowing the user's business logic controller to be detached from the servlet API. The STRUTS2 controller component is the core of the STRUTS2 framework, in fact all of the MVC frameworks are core to the controller components. As mentioned earlier, the STRUTS2 controller consists of two parts: the Filterdispatcher and the Business controller action.

Using interceptors as processing (Advice), a controller agent is created to target the user's business logic controller. The controller agent is responsible for handling user requests and callback the Execute method of the business controller when the user requests are processed, and the method return value determines what view resources are rendered.

The STRUTS2 system overview is as follows:

2, Struts2 processing process

(1), the browser sends the request. such as Mypage.action

(2), the core controller Filterdispatcher decides to invoke the appropriate action on request.

(3), webwork interceptors automatically apply common functions to the request, such as workflow, validation or file upload, etc.

(4), callback action of the Execute method, the Execute method first obtains the user request parameter, then performs some kind of database operation, can be either saves to the database, may also retrieve the information.

(5), Action's Execute method processing result information will be sent to the browser. and support a lot of view technology.

3. Comparison of Struts2 and Struts1

(1), in the Action implementation class: STRUTS1 requires an action to inherit an abstract base class, not an interface, STRUTS2 can be implemented, and provides a actionsupport base class to implement the commonly used interfaces.

(2), threading mode aspect: Struts1 action is a singleton pattern and must be thread safe because there is only one action instance that handles all requests. STRUTS2 does not have a thread safety issue because the action object generates an instance for each request.

(3), servlet dependency: Struts1 action relies on the servlet API, but Struts2 does not depend on it.

(4), testable: Struts1 action is not easy to test. Struts is easy to test.

(5), Expression language aspects: Struts1 can use JSTL,STRUTS2 can also be used jstl, but more support OGNL

(6), bind value to view: Struts1 uses JSP mechanism. STRUTS2 uses Valuestack technology to enable the tag library to access values without having to bind objects and view pages together.

(7), type conversion: Struts1 Actionform properties are usually string type, using Commons-beanutils for type conversion, each class one converter, the converter is not configurable. STRUTS2 uses OGNL for type conversion, which supports conversions between basic data types and common objects.

(8), data check: STRUTS1 support in Actionform Override Validate method, Manual Check, or through the Commons Alidator framework to complete the verification. STRUTS2 supports overriding the Validate method and also supports Xwork checksums.

(9), acion execution Control: Struts1 Each module corresponds to a request processing, each module must share the same life cycle. STRUTS2 supports creating different lifecycles for each action through the interceptor stack. Developers can create stacks as needed to work with different action.

Struts1, WebWork, Struts2 Introduction

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.