This Presentation will give you an overview of
the Struts framework showing you the basic
components you need to be familiar with in
order to create a Web application using Struts.
• Understand what is Struts and its benefits as an
• Understand the Model-View-Controller design
• Understand how an Struts application is
What are OO Application
• Frameworks are reusable, “semi-complete''
applications that can be applied to produce
• Frameworks are tested, proven software
designs and implementations that reduce the
cost, accelerate development speed and
improve the quality of software
Benefits of using OO Application
• Provide developers with modular, reusable and
extensible software components
• Modular frameworks reduce the time and effort and
investment required to understand and maintain
• Fosters reuse. Contributes improvements in
programmer productivity, as well as enhancing the
quality, performance, reliability and interoperability
• Extensibility is essential to ensure timely
customization of new application services and
• Reduces the cost of building and maintaining
Business benefits of using OO
Frameworks & Tools
• Adherence to standards
• Uniformity of Code
• Accelerates Software Development
• Reduces cost of development and maintenance
• Reduces developer intervention
What is the Struts Framework?
• Struts is an open source framework created within the
Jakarta project by the Apache Software Foundation
• Struts is a JSP/Servlet framework for building J2EE
• Struts accelerates application development based on
the Model-View-Controller (MVC) design pattern
• For more info on struts go to:
What is the MVC Pattern?
• Is an abstract design pattern for software
applications that was first introduced on the
• The goal of the MVC design pattern is to
separate the application object (model) from
the way it is represented to the user (view)
from the way in which the user controls it
What are the components within
the MVC Pattern?
• The model provides a representation of the data to the
components comprising the view. It also knows about
all the operations that can be applied to transform the
data. It knows nothing about how it is being viewed
by the users.
• The view provides presentation services in the
application, such as a data entry screen or a screen
rendering a query result .
• The controller is responsible for linking the
view with the model. The controller can be
thought of as the controlling influence on the
state of the model. All paths of navigation in
the application are channeled through the
Benefits of using the MVC Pattern
• Widely accepted design pattern
• Clarity of Design
• Easy to create multiple views of the business
The MVC Used in Web Apps
• The MVC design pattern has now been
adapted to build Web Applications.
• The adapted pattern is known as the Model2
• The model is represented by JavaBeans or
• The view is represented by JSPs
• The controller is represented by a Servlet.
What is the Struts Architecture?
• The model is comprised of a combination of EJBs,
Java Beans, and a set of Java classes extending the
Struts base class ActionForm
• The view is represented by JSPs.
• The controller is implemented by the Struts
• You can extend the controller’s behavior by creating
Action classes to trigger the execution of a user
• You integrate all these components by updating your
web.xml file and the struts-config.xml file
What is the Struts Architecture?
• The view is implemented as JSPs that render
presentation elements using both standard JSP
tags and JSP Tag Extensions
• The use of JSP Tag Extensions eliminates the
need for lots of messy processing logic and
custom processing embedded in the
How to build a Struts application?
• Build the Model Components (ActionForm
• Build the Controller Components (Action
• Build the View Components (JSPs)
• Create the struts-config file
• Update the web.xml file
Building an ActionForm
• The ActionForm (also called the form) is a data
holder that contains the data entered trough an HTML
• The form contains member variables related to each
property that may be submitted within an HTML
• The form should also contain the get & set methods
for each property.
• The form may also implement a validate
method to perform data entry validations
before actually performing the requested
• To create a form, you will need to extend the
Building an Action
• The Action is an object used to extend the behavior of
• An action implements a perform method that is called
by the ActionServlet when an request is subimtted.
• A sample Action may be a SearchAction responsible
for performing a DB query .
• Action classes should only process the data available
in the form and should delegate the actual business
processing to a JavaBean or EJB (model)
• To create an Action, you will need to extend the class
Building a JSP
• To create a JSP using Struts you will use the tag
libraries provided by the Struts Framework.
• struts-logic.tld : This tag library contains tags that are
useful in managing conditional generation of output
text, looping over object collections for repetitive
generation of output text, and application flow
• struts-html.tld : This taglib contains tags used to
create struts input forms, as well as other tags
generally useful in the creation of HTML-based user
Building a JSP
• struts-bean.tld :This tag library contains tags useful
in accessing beans and their properties, as well as
defining new beans
• struts-template.tld : This tag library contains three
tags: put, get, and insert. Put tags put content into
request scope, which is retrieved by a get tag in a
different JSP page (the template).
• You can get more information on the tag libraries at:
Create the struts-config.xml file
• To allow for better reusability, all components in
Struts are loosely coupled.
• To integrate the components you must create a config
• Within this file you’ll define the action-mappings and
• The action-mappings tell the ActionServlet which
action classes to include within the application.
• The form-beans define the ActionForm classes
required within the application.
The web.xml file
• The final step in setting up an web application
using Struts is to configure the application
deployment descriptor (stored in file WEB-
INF/web.xml) to include all the Struts
components that are required.
• You will need to configure the Action Servlet
• You will then configure the Action Servlet
• And you will configure the Struts Tag Library
Benefits of using Struts
• Encourages standardization of the presentation
elements by promoting code reuse
• Offers an extensive collection of ready-to-use
custom JSP tags
• Logic tags perform conditional processing,
• Proven architecture for building JSP/Servlet
A particular slide catching your eye?
Clipping is a handy way to collect important slides you want to go back to later.