Struts

Understanding the Model-View-Controller Design Pattern
adplus-dvertising
Previous Home Next

An Application framework is a skeleton of an application that can be customized by the application developer as needed. Struts is an application framework that unifies the interaction of the various components of a J2EE Web application such as JavaServlets, JavaServer pages, JavaBeans, and Business logic — into one consistent whole. Struts provides this unification by implementing the Model-View-Controller (MVC) design pattern for web application.

The MVC pattern separates responsibilities into three layers of functionality:

  • Model -Action -- The data and Business logics.
  • View -Result -- The presentation.
  • Controller- FilterDispatcher -- The flow control.

CONTROLLER—FILTERDISPATCHER

The controller's main job is to map requests to action i.e. the controller is the first component to act in the processing. The Controller handles all requests from the user and selects the view to return. When the Controller receives a request from user, Controller forwards the request to the appropriate handler, which interprets what action to take based on that request. The Controller calls on the Model to perform the desired function. After the Model has performed the function, the Controller selects the View to send back to the user based on the state of the Model’s data.

In the Web application, the incoming HTTP requests can be thought of as commands that the user issues to the application. One of the fundamental tasks of a web application is routing these requests to the appropriate set of actions that should be taken within the application itself.

The FilterDispatcher is introduce into struts 2 framework. This important object is a servlet filter that inspects each incoming request to determine which Struts 2 action should handle the request.

MODEL—ACTION

The model is the internal state of the application which provides necessary access to the business data as well as the business logic needed to manipulate that data. The Model typically has some means to interact with persistent storage — such as a database — to retrieve, add, and update the data.

In Struts 2 action serves play two important roles.

An action is an encapsulation of the calls to business logic into a single unit of work.

The action serves as a locus of data transfer.

However, the developer of the Model components will be focusing on the creation of JavaBeans classes that support all of the functional requirements. The precise nature of the beans is completely widely depend upon the requirement of project. So the scope of Beans are:-

  • page :- Beans request that visible within a single page or servlet( in which Bean is create)
  • request :- Bean request that visible within a single page as well as to any page or servlet that is included in this page, or forwarded to by this page.
  • Session :- Bean request that visible into many pages or servlet until the particular user session not expire.
  • Application :- Bean request visible within the web application.

VIEW—RESULT

The view is the presentation component of the MVC pattern. The View is responsible for displaying data from the Model to the user. This layer also sends user data to the Controller. View pages are commonly JSP pages, JSF page, HTML pages, Velocity templates, or some other presentation-layer technology.

Previous Home Next