Saturday, July 23, 2011

Introduction to Struts 2 Framework

Firstly I will tell you about framework, What exactly it is? A web application framework is a piece of structural software that provides automation of common tasks of the domain as well as providing a built in architectural solution that can be easily inherited by applications implemented on the framework.

The Struts 2 Framework

Struts 2 is a new release of the older Struts1 web application framework. It is a completely new framework, based on the architecturally esteemed WebWork framework. Struts 2 is a second generation web application framework that implements the Model-View-Controller (MVC) design pattern. From the previous version of struts now we have certainly new things to learn, interceptors & OGNL (Object-Graph Navigation Language) in particular. The whole point of design patterns such as MVC is the reuse of solutions to common problems. Reusing solutions at the architectural level provides an easy transferal of experience and knowledge.

The MVC Pattern


The MVC pattern provides a separation of concerns that applies well to the domain of web applications. Separation of concerns allows us to manage the complexity of large software systems by dividing them into high level components. The MVC design pattern identifies three distinct concerns: model, view and controller. In Struts 2 these concerns are implemented by the action, result and FilterDispatcher, respectively.

How Struts 2 Works

The framework has more than just its MVC components. Struts 2 provides a cleaner implementation of MVC. These clean lines are only possible with the help of a few other key architectural components that participate in the processing of each and every request. The most important are Interceptor, OGNL and the ValueStack. In Struts 2, FilterDispatcher has already done its controller work. In this, framework has already selected an action and has initiated the invocation process. This workflow in this figure is simply flows the MVC. An action has been selected by the controller, it will execute, and then select the appropriate result. The rest of the stuff mostly serves to make that basic MVC workflow cleaner. In Struts 2 framework, interceptor is the component that execute both before and after the rest of the request processing. Interceptors provide an architectural component in which to define various workflow and other crosscutting tasks so that they can be easily reused as well as separated from other architectural concerns.
In the framework,ValueStack is simply a storage area that holds all of the application domain data associated with the processing of a request. and last one OGNL, is a powerful expression language that allows you to reference and manipulate the data on the ValueStack.