Struts Tutorial

This tutorial will contain the various aspects of Struts such as what is struts, features of struts, architecture of struts, download and install struts, struts actions, struts logic tags, struts integration with other framework, struts validator framework.

Struts Tutorial

In this section we will discuss about Struts.

This tutorial will contain the various aspects of Struts such as What is Struts, features of struts, Architecture of Struts, download and install struts, struts actions, Struts Logic Tags, struts integration with other framework, Struts Validator Framework.

What is Struts ?

Struts is an open source MVC based framework for developing web applications. Craig McClanahan was the creator of Struts and later it donated to Apache Foundation. Struts allows for the web form components, validation, internationalization, error handling, tiles layout etc. Struts framework is also called web framework. Struts is created on MVC based so it separates the model from view and the controller. Struts framework provides the following three key components :

  • Request handler (provided by the application developer).
  • Response handler (handles the response to complete it even if control is transferred to another resource for completing the response).
  • Tag library (facilitate developers to create more effective form-based applications).

Features of Struts

Struts has various of features some of them are as follows :

  • Struts provides the POJO based actions.
  • Thread safe.
  • Struts has support of AJAX
  • Struts has the template support.

Architecture of Struts

Struts is based on the MVC architecture that defines the business logic, application data and the presentation data separately. Struts framework is composed with the various of classes and interfaces, organized into different packages. It has also support of the utility and helper classes. Following is the view of the Struts architecture :

  • Struts Model Component : Provides Model of the business logic.
  • Struts View Component : Takes the input from the user and provide the information to them.
  • Struts Controller Component : In Controller, Action class handles the request and communicate with the model layer.

Versions Of Struts

Struts is also released in various versions. Struts major versions are popularly known as Struts 1, and Struts 2 (till the time of writing this tutorial). Their sub versions are as :

  • struts 2.3.14 (latest version till the writing of this tutorial)
  • struts 2.3.1
  • struts 2.2.1
  • struts 2.0.6
  • struts 1.1

Download And Install Struts

Struts is available as open source and it is released by the Apache Software foundation, so you can download Struts from the Apache Software Foundation's website. You can follow this link to download Struts You can select the specific version of Struts and download.

Struts Built-In Actions

Struts provide the built-in actions that facilitate the various functionalities useful to diverse applications. Some of the Built-in classes are as :

  • org.apache.struts.actions.DispatchAction
  • org.apache.struts.actions.ForwardAction
  • org.apache.struts.actions.LocaleAction
  • org.apache.struts.actions.MappingDispatchAction

Struts Logic Tags

Struts logic tags helps developer in to generate the html output based on different control statements. Some of the Struts Logic Tags are as :

  • empty
  • equal
  • forward
  • greaterEqual
  • iterate

Struts Integration With Other Framework

Struts is capable to integrate with the other frameworks like, Hibernate, Spring, JSF.

Struts And Validation

Validation is the main feature of any web-application. It is useful in several cases such as validating for number input, character input, empty field, null input. In Struts these validation is possible due to validation framework. Validation framework needed two XML files named validator-rules.xml and validation.xml