Getting started with struts framework

Today the Struts Framework is a standard for developing web applications in java. The Struts is the best framework for building Java-based web applications. Using the Model-View-Controller (MVC) design pattern, The Struts framework solves many of the problems associated with developing high-performance, business-oriented web applications that use Java Servlets and JSP Pages.

The struts framework has the following features:

The Struts framework is based on the Model-View-Controller (MVC) design pattern, so it also called as struts MVC framework. The MVC pattern separates business logic from presentation layer.

The Struts framework implements the JSP Model 2 Architecture.

The Struts framework stores application routing information and request mapping in a single core file, and that file is struts-config.xml

The Struts Framework comes with the View and Controller layers; only the model layer is left to the developer to write their business logic.

The basic components of struts

The Struts framework is a collection of Java libraries and it can be broken down into the following major pieces as:

Core framework

JSP tag libraries

Tiles framework

Validator framework

We will take a closer look of each of these pieces.

The core framework

The core framework provides the core MVC functionality and consists of the building blocks for your application.

ActionServlet: The ActionServlet play controller role in struts MVC framework. This is the Controller servlet class is the foundation of the core framework. Your each request will go through this controller servlet.

The rest of the code framework is composed of core classes that your application classes will extend and several utility classes. The most prominent among the base classes are. These two classes are used extensively in all Struts applications.

Action: The Action classes used by ActionServlet to process the specific request.

ActionForm: The ActionForm classes are used to capture data from HTML forms and to be a conduit of data back to the View layer for page generation.

The JSP Tag Libraries

The Struts framework comes with several JSP custom tag libraries for using view logic in JSP pages. The JSP tag libraries enable JSP developer to use HTML like tags to represent functionality that is defined by a Java class.

Below is the list of the tag libraries and their use which comes with struts framework:

HTML: The html tag libraries used to generate HTML forms and HTML controls that interact with the Struts APIs.

Bean: The bean tag libraries used to work with Java bean objects in JSPs, such as accessing bean values, in addition of displaying the messages from properties file.

Logic: The logic tag libraries used to cleanly impalement simple conditional logic in JSPs.

Nested: The nested tag libraries used to simplify access to arbitrary levels of nested objects from the HTML, Bean, and Logic tags.

The struts tiles framework

The struts framework comes with the Tiles framework. The tile is a rich JSP templating framework that facilitates the reuse of presentation code like HTML or JSP. Using tiles framework the JSP pages can be broken up into individual “tiles” or pieces and then glued together to create one cohesive page. Similar to the design principles that the core Struts framework is built on, Tiles provides excellent reuse of View code.

The tiles framework in optional to use, you can configure tiles in struts configuration file using tiles plug-in.

The struts validator framework

The struts framework also comes with validator framework with the Jakarta Commons Validator framework for performing data validation. Validator provides a rich framework for performing data validation on both the server side and the client side. You can configure each validation in an outside XML file so that validations can easily be added to and removed from an application declaratively versus being hard-coded into the application.

The validator framework in optional to use, you can configure tiles in struts configuration file using validator plug-in.