Introduction to Struts 2

This section provides you a quick introduction to Struts 2 framework. This section we are discussing the new features, struts 2 basics and architecture.

Introduction to Struts 2

Introduction to Struts 2

     

This section provides you a quick introduction to Struts 2 framework. This section we are discussing the new features, struts 2 basics and architecture.

Struts and webwork has joined together to develop the Struts 2 Framework. Struts 2 Framework is very extensible and elegant for the development of enterprise web application of any size.

The Struts 2 framework is designed for simplifying the entire development cycle including building, developing and maintaining the whole application. It is very extensible as each class of the framework is based on an Interface and all the base classes are given an extra application and even you can add your own. The basic platform requirements are Servlet API 2.4, JSP API 2.0 and Java 5. 

Video Tutorial - Introduction to Struts 2 Framework

 Features of Struts 2

  • Simplified and easily web application development
  • All framework classes are based on interfaces and core interfaces are independent from HTTP. 
  • Check boxes do not require any kind of special application for false values.
  • Any class can be used as an action class and one can input properties by using any JavaBean directly to the action class. 
  • Struts 2 actions are Spring friendly and so easy to Spring integration. 
  • AJAX theme enables to make the application more dynamic. 
  • Portal and servlet deployment are easy due to automatic portlet support without altering code.
  • The request handling in every action makes it easy to customize, when required.
  • Struts is designed to boost the productivity

Architecture of Struts 2 Application

Here we are explaining the architecture of Struts 2 Framework.

Struts 2 Framework is based on MVC (Model-View-Controller) architecture. The logic behind the MVC architecture is to separate all the three parts the object model of the application, the view through which the user interacts with the application and the controller that controls the all the processing done by the application.

  • Model
    The model part represents the enterprise data and the rules that are governed to access and update the data.
      
  • View
    The view part provides interface with the outside world to our application. A single model can have multiple view for different purposes. The view object defines the way how the data is to be presented. View object is responsible for maintaining the consistency in data presentation whenever the model changes.
      
  • Controller 
    The controller controls the user interaction between the view and model. The controller does not includes any business logic. It also strictly deals with exposing of methods included in the model to the user through the view. The controller controls the updation of a particular parameter in the view which is then displayed by a view. Based on the outcome of the interaction with the user and model, the controller determines the appropriate view.

The Flow of Struts 2 based Application

Here is the Request Lifecycle in Struts 2 applications:

  1. User Sends request: User sends a request to the server for some resource.  
  2. FilterDispatcher determines the appropriate action: The FilterDispatcher looks at the request and then determines the appropriate Action.  
  3. Interceptors are applied: Interceptors configured for applying the common functionalities such as workflow, validation, file upload etc. are automatically applied to the request.  
  4. Execution of Action: Then the action method is executed to perform the database related operations like storing or retrieving data from the database.  
  5. Output rendering: Then the Result renders the output.  
  6. Return of Request: Then the request returns through the interceptors in the reverse order. The returning request allows us to perform the clean-up or additional processing.  
  7. Display the result to user: Finally the control is returned to the servlet container, which sends the output to the user browser.

Struts 2 is a very elegant and flexible front controller framework based on many standard technologies like Java Filters, Java Beans, ResourceBundles, XML etc.

For the Model, the framework can use any data access technologies like JDBC, EJB, Hibernate etc and for the View, the framework can be integrated with JSP, JTL, JSF, Jakarta Velocity Engine, Templates, PDF, XSLT etc.

To know more about struts2 click on the link www.roseindia.net/struts/struts2.