Struts Tutorial

The struts 2 framework is used to develop MVC-based web application.

It is a brand new framework which provides the facility of developing web application based on MVC design pattern. The main features provided by this framework are-

  1. It is a non intrusive framework.
  2. It favors conventions over configuration.
  3. To support annotation based (@) configuration in addition to XML based configuration
  4. It supports the concept of dependency injection and aspect oriented programming.
  5. It supports the concept of OGNL expression and value stack for sharing data among different components.
  6. It supports multiple view technologies like JSP, AJAX, JSF, velocity template, HTML, java sprit etc.

About Struts 2 Framework

Struts 2 is based on the OpenSymphony Web Works Framework.

Struts 2 framework implements the Model-View-Controller (MVC) design pattern.

In Struts 2 the model, view and controller are implemented by the action, result and FilterDispatcher respectively.

The controller's job is to map the user request to appropriate action.

In Struts 2 FilterDispatcher does the job of Controller.

Model contains the data and the business logic.

In Struts 2 the model is implemented by the Action component.

View is the presentation component of the MVC Pattern.

In Struts 2 the view is commonly implemented using JSP, Velocity Template, Freemaker or some other presentation-layer technology.

MVC (Model View Controller)

It is a design pattern that proposes to divide the functionality of an application in to 3 loosely connected component call model, view and controller. Model represents data or state of an application. View represents presentation or how the data is to be presented to the end user and controller represents the work flow of the application. Work flow represents sequence of steps or manipulation to be performed in order to change an application.

The advantage of using MVC design pattern are-

  1. Reusability
  2. Ease of maintenance
  3. Non procreative work flow description

Struts 2.0 implementation of MVC

In struts 2.0 Action represents model components and Action is a POJO class (Plain old java object) that encapsulate data and processing logic in a single unit. Action is responsible for changing the state of an application.

NOTE: In struts 1.0 model component is used to represent only data. In struts 2.0 model represent data+ logic.

Result- component of struts are represented for generation view. Result is a generic component, multiple implementations of which is provided by framework to support different presentation technologies such as JSP, JSF, velocity template, AJAX, silver light, javaFX.

FilterDispatcher- is the controller implementation provided by the framework. It is a filter which provides a single entry point in to the application and controls the processing of the request.