-
Apache Struts is an open-source web application framework for developing Java EE web applications.
-
It uses and extends the Java Servlet API to encourage developers to adopt a model-view-controller (MVC) architecture.
-
It was originally created by Craig McClanahan and donated to the Apache Foundation in May, 2000.
-
Formerly located under the Apache Jakarta Project and known as Jakarta Struts, it became a top-level Apache project in 2005.
-
The goal of Struts is to separate the model (application logic that interacts with a database) from the view (HTML pages presented to the client) and the controller (instance that passes information between view and model).
-
Struts provides the controller (a servlet known as ActionServlet) and facilitates the writing of templates for the view or presentation layer (typically in JSP, but XML/XSLT and Velocity are also supported).
-
The web application programmer is responsible for writing the model code, and for creating a central configuration file struts-config.xml that binds together model, view and controller.
-
Struts also supports internationalization by web forms, and includes a template mechanism called “Tiles” that (for instance) allows the presentation layer to be composed from independent header, footer, and content components.
A framework is a set of classes and interfaces that cooperate to solve a specific type of software problem.
Framework characteristics
- A framework is made up of multiple classes or components, each of which may provide an abstraction of some particular concept.
-
The framework defines how these abstractions work together to solve a problem.
-
The framework components are reusable.
-
A good framework should provide generic behavior that can be utilized across many different types of applications.
Framework Drawbacks
- Frameworks are not flexible – Changes unacceptable to the provider.
-
Frameworks impose a way of thinking – Design and code according to the framework.
-
Frameworks increase the learning curve.
-
Not suited for smaller applications.

Controller Components
- ActionServlet -(Framework provided)
-
RequestProcessor – (Framework provided)
-
ActionClasses – (You have to build these)
ActionServlet and RequestProcessor (What Do They Really Do?)
- Receive the HttpServletRequest
-
Automatically populate a JavaBean from the request parameters
-
Handle Locale and Content Type Issues
-
Determine which Action to invoke based on URI
-
Provide extension points
ActionServlet Facts
- Extends javax.servlet.http.HttpServlet
-
Receives all framework requests
-
Selects proper application module
-
Delegates request handling to the RequestProcessor instance
-
One ActionServlet instance per web application
-
Default implementation provided by framework (can extend if necessary)
-
May go away in future versions
The RequestProcessor Class
- One instance per application module
-
Processes all requests for module
-
Invokes proper Action instance
-
Default implementation provided by framework (can extend if necessary)
ActionServlet and RequestProcessor Diagram

What is an Action Class?
- Extends org.apache.struts.action.Action
-
Overrides the execute() method
-
Acts as a bridge between user-invoked URI and a business method (Command pattern)
-
Returns information about which view should be rendered next
-
Part of the Controller, not the Model
Action Class Diagram

Example of Action Class

Struts Includes Pre-built Action Classes
- ForwardAction
-
DispatchAction
-
LookupDispatchAction
-
IncludeAction
-
SwitchAction
Struts Model Components
- No built-in support for the model
-
No model components provided
-
Framework supports any component model (JavaBeans, EJB,Corba, JDO, etc.)
-
Should always decouple the application from a specific model implementation.
Design Patterns Used in Struts
-
Model-View-Controller
-
Front Controller
-
Session Facade
-
Service Locator
-
Data Transfer Object (a.k.a ValueObject)
-
Command
-
Business Delegate
-
Factory
-
Data Access Object
-
Service to Worker

View Components
-
JavaServer Pages
-
HTML
-
JavaScript and Stylesheets
-
Multimedia Files
-
Resource Bundles
-
JavaBeans (Part of model used by views)
-
JSP Custom Tags
-
ActionForms
Struts JSP Tag Libraries
-
HTML
-
Bean
-
Logic
-
Nested
-
Tiles
-
Template
Nested Tag Benefits
-
Tags can have a relationship
-
Fewer attributes must be defined
-
Can work against a single level
-
Change is more manageable
What is an ActionForm?
-
Java class that extends the org.apache.struts.action.ActionForm
-
Captures user data from the Http request
-
Stores the data temporarily
-
Acts as a “firewall” between the presentation tier and the application
-
Provides the ability to validate the user input
Struts 1.x :: Struts 1.0, 1.1, 1.2, 1.3 :: Struts 1.3 is the last production release of Struts 1
- Struts is a flexible control layer based on standard technologies like Java Servlets, JavaBeans, ResourceBundles, and XML, as well as various Apache Commons packages, like BeanUtils and Chain of Responsibility. The framework helps you create an extensible development environment for your application, based on published standards and proven design patterns.
- The framework provides its own web Controller component and integrates with other technologies to provide the Model and the View. For the Model, the framework can interact with standard data access technologies, like JDBC and EJB, as well as most any third-party packages, like Hibernate,iBATIS, or Object Relational Bridge. For the View, the framework works well with JavaServer Pages, including JSTL and JSF, as well as Velocity Templates,XSLT, and other presentation systems.
- The framework’s Controller acts as a bridge between the application’s Model and the web View. When a request is received, the Controller invokes an Action class. The Action class consults with the Model (or, preferably, a Facade representing your Model) to examine or update the application’s state. The framework provides an ActionForm class to help transfer data between Model and View.
- Most often, the Model is represented as a set of JavaBeans. Typically, developers will use the Commons BeanUtils to transfer data between ActionForms and the Model objects (or a Facade). Preferably, the Model will do the “heavy lifting”, and the Action will act as a “traffic cop” or adapter.
Struts 2.x :: Struts 2.0, 2.1, 2.2 :: Apache Struts 2.2 is an elegant, extensible framework for creating enterprise-ready Java web applications.
- Apache Struts 2 is an elegant, extensible framework for creating enterprise-ready Java web applications. The framework is designed to streamline the full development cycle, from building, to deploying, to maintaining applications over time.
- Apache Struts 2 was originally known as WebWork 2. After working independently for several years, the WebWork and Struts communities joined forces to create Struts2. This new version of Struts is simpler to use and closer to how Struts was always meant to be.
Build!
- Easy startup – Jumpstart new projects with our bootstrap tutorial and template application or Maven archetype.
-
Improved Design – Code clean against HTTP-independant framework interfaces.
-
Enhanced Tags – Code less with stylesheet-driven form tags that provide their own markup.
-
Stateful Checkboxes – Avoid special handling with smart checkboxes that know when they are toggled.
-
Flexible Cancel Buttons – Go directly to a different action on cancel.
-
First-class AJAX support – Add interactivity and flexibility with AJAX tags that look and feel just like standard Struts tags.
-
Easy Spring integration – Inject dependencies into Actions using Spring without glue code or red tape. (Plexus support also available.)
-
Enhanced Results – Do more with speciality results for JasperReports, JFreeChart, Action chaining, and file downloading.
-
POJO forms – No more ActionForms! Use any JavaBean to capture form input or put properties directly on an Action class. Use both binary and String properties!
-
POJO Actions – Use any class as an Action class — even the interface is optional!
Deploy!
- Easy plugins – Add framework extensions by dropping in a JAR. No manual configuration required! Bundled plugins add support for JavaServer Faces, JasperReports, JFreeChart, Tiles, and more …
-
Integrated profiling – Peek inside Struts2 to find where the cycles are going!
-
Precise Error Reporting – Flip directly to the location and line of an error.
Maintain!
-
Easy-to-test Actions – Test Struts2 Actions directly, without resorting to mock HTTP objects.
-
Intelligent Defaults – Skip obvious and redundant settings. Most framework configuration elements have a default value that we can set and forget. Say it once!
-
Easy-to-customize controller – Customize the request handling per action, if desired. Struts2 only does what you want it to do!
-
Integrating Debugging – Research problem reports with built-in debugging tools.
-
Easy-to-tweak tags – Customize tag markup by editing a FreeMarker template. No need to grok the taglib API! JSP, FreeMarker, and Velocity tags are fully supported.
Apache Struts 2 requires
- Servlet API 2.4
-
JSP API 2.0
-
Java 5
Why consider Struts?
- Developed by Industry Experts
-
Stable & Mature
-
Manageable learning Curve
-
Open Source
-
1700 member User Community (50-100 new members each month)
-
It’s probably similar to what you would build if not using Struts
-
Good documentation – 5 books available soon!
-
Feature-rich
-
Free to develop & deploy
-
Many supported third-party tools
-
Flexible & Extendable
-
J2EE Technologies
-
Expert Developers and Committers
-
Large User Community
-
Performance
Struts Dependencies
-
Java 1.2 or newer
-
Servlet 2.2 and JSP 1.1 container
-
XML parser compliant with JAXP 1.1 or newer (e.g. Xerces)
-
Jakarta Commons packages
-
JDBC 2.0 optional package
-
Model 2 -MVC Implementation
-
Internationalization(I18N) Support
-
Rich JSP Tag Libraries
-
Based on JSP, Servlet, XML, and Java
-
Supports Java’s Write Once, Run Anywhere Philosophy
-
Supports different model implementations (JavaBeans, EJB, etc.)
-
Supports different presentation implementations( JSP, XML/XSLT, etc)
-
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.
-
Strut 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.
Click Here to Download the code for FirstStruts Example
Organize your file as Below

Code for HelloAction Class









1. Struts 1.2 API Documentation
2. Struts 2.0 API Documentation
Recent Comments