INTRODUCTION TO STRUTS
Struts is Java MVC framework for building web applications on the J2EE platform. It is a serverside Java implementation of the Model-View-Controller (MVC) design pattern.
To understand Struts Framework, we must have a fundamental understanding of the MVC design pattern, The MVC design pattern, which originated from Smalltalk, consists of three components: a Model, a View, and a Controller.
Model Represents the data objects. The Model is what is being manipulated and presented to the user.
View Serves as the screen representation of the Model. It is the object that presents the current state of the data objects.
Controller Defines the way the user interface reacts to the user’s input. The Controller component is the object that manipulates the Model, or data object.
Benefits of the MVC include:
Reliability
The presentation and transaction layers have clear separation, which allows us to change the look and feel of an application without recompiling Model or Controller code.
High reuse and adaptability:
The MVC lets us use multiple types of views, all accessing the same server-side code.
Very low development and life-cycle costs:
The MVC makes it possible to have lower-level programmers develop and maintain the user interfaces.
Rapid deployment:
Development time can be significantly reduced because Controller programmers (Java
developers) focus solely on transactions, and View programmers (HTML
and JSP developers) focus solely on presentation.
Maintainability:
The separation of presentation and business logic also makes it easier to maintain and modify a Struts-based Web application.
Model Represents the data objects. The Model is what is being manipulated and presented to the user.
View Serves as the screen representation of the Model. It is the object that presents the current state of the data objects.
Controller Defines the way the user interface reacts to the user’s input. The Controller component is the object that manipulates the Model, or data object.
Benefits of the MVC include:
Reliability
The presentation and transaction layers have clear separation, which allows us to change the look and feel of an application without recompiling Model or Controller code.
High reuse and adaptability:
The MVC lets us use multiple types of views, all accessing the same server-side code.
Very low development and life-cycle costs:
The MVC makes it possible to have lower-level programmers develop and maintain the user interfaces.
Rapid deployment:
Development time can be significantly reduced because Controller programmers (Java
developers) focus solely on transactions, and View programmers (HTML
and JSP developers) focus solely on presentation.
Maintainability:
The separation of presentation and business logic also makes it easier to maintain and modify a Struts-based Web application.
The Struts Implementation of the MVC
The Struts Framework models its server-side implementation of the MVC using a combination of JSPs, custom JSP tags, and Java servlets.
Figure depicts the route that most Struts application requests follow. This process can be broken down into five basic steps. Following these steps is a description of the ActionServlet and Action classes.
1. A request is made from a previously displayed View.
2. The request is received by the ActionServlet, which acts as the Controller, and the ActionServlet looks up the requested URI in an XML file and determines the name of the Action class that will perform the necessary business logic.
3. The Action class performs its logic on the Model components associated with the application.
4. Once the Action has completed its processing, it returns control to the ActionServlet. As part of the return, the Action class provides a key that indicates the results of its processing. The ActionServlet uses this key to determine where the results should be forwarded for presentation.
5. The request is complete when the ActionServlet responds by forwarding the request to the View that was linked to the returned key, and this View presents the results of the Action.
The Model
The Struts Framework does not provide any specialized Model components; therefore, we will not dedicate an entire chapter to the Model component. Instead, we will reference Model components as they fit into each example.
The View
Each View component in the Struts Framework is mapped to a single JSP that can contain any combination of Struts custom tags.
The Controller
The Controller component of the Struts Framework is the backbone of all Struts Web applications. It is implemented using a servlet named org.apache.struts.action.ActionServlet.This servlet receives all requests from clients, and delegates control of each request to a user-defined org.apache.struts.action.Action class. The ActionServlet delegates control based on the URI of the incoming request. Once the Action class has completed its processing, it returns a key to the ActionServlet, which is then used by the ActionServlet to determine the View that will present the results of the Action’s processing. The ActionServlet is similar to a factory that creates Action objects to perform the actual business logic of the application.

No comments:
Post a Comment