Origin and Architecture of Struts

By: Fanny Ong Emailed: 1698 times Printed: 2188 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

Craig McClanahan originally wrote the Struts framework, mostly while on his Memorial Day vacation in 2000! The framework was subsequently donated by Craig to the Apache Software Foundation. The fact that it was mostly written in one weekend should suggest to you that it’s a very simple framework.

You should also note that anything that can be done with JSP pages and servlets can still be done with Struts. So you can still write regular servlets that extend HttpServlet in your application or have JSP pages with whatever embedded scriplet code you want. On the other hand, Struts does try to encourage certain better practices for coding web applications, and it does make it easier to write and deploy them. For instance, when using Struts, you don’t need to write a whole slew of request.getParameter() calls in your servlet to get all your form’s values. Struts does this for you with an ActionForm, which handles the population and grabbing of an HTML form’s values.

A web framework provides a set of services that can be used and reused across many different web applications. Struts is an open-source web framework that is based upon the tried-andtrusted MVC design pattern. Its core is made up of Java servlets, JavaBeans, resource bundles, XML, and tag libraries. Struts provides the following services:

  • A controller servlet

  • Ready-made tag libraries

  • A framework for internationalizing messages

  • A generic error and exception-handling mechanism

  • XML parsing

  • File upload and logging utilities

Struts Architecture

So how do these ActionForms fit into the overall Struts architecture? Figure below shows a schematic of a simple Struts application in general.

First, you can see that we’ve assumed that you’re using JSP pages for the view, and that these are built using the Struts tag libraries. Each client request for the application to perform a particular action is passed to the controller servlet (known as the ActionServlet), which dispatches to an Action class.

Each Action class extends org.apache.struts.action.Action. Every Action provides application-specific implementation by overriding the execute() method. The business logic needed to perform each action (process each type of request) is present in this corresponding Action class in the execute() method. The Action classes represent the controller logic for your application. They control which view elements are presented to the user. For instance, if an error occurs, the action is responsible for displaying errors on an input page.

There also may be a corresponding ActionForm JavaBean class for each action. The ActionForm class extends org.apache.struts.action.ActionForm and overrides the validate() method. Each ActionForm validates user data and can be used by the Action class to retrieve user data. The ActionForm classes represent the data of the model. The model is your data and the code you write to retrieve, save, or delete that data.

So, as you would expect from the controller, the ActionServlet provides the link between the view and the Action and ActionForm model components. To do this it needs to map the request data to the appropriate Action and ActionForm classes, depending upon the action requested by the client. The correct mapping of request actions to Action and ActionForm classes is defined in a configuration file, struts-config.xml (defined by http://struts.apache.org/dtds/struts-config_1_2.dtd). This file defines a set of ActionMapping objects that each represents a mapping of an action to the appropriate model classes. Therefore, the ActionServlet checks this struts-config.xml file to find the appropriate mapping for the current request.

Finally, if the Action class processes the request correctly, it indicates to the ActionServletwhere the user should be forwarded to (usually a JSP page), by passing the ActionServlet an ActionForward object.

For more in-depth information about the architecture and implementation of the Struts framework, you can try pointing your browser to the following links:

• http://jakarta.apache.org/struts/: Struts homepage (you can download the latest version from here)

• http://struts.apache.org/userGuide/index.html: Struts user guide

As you may have spotted already, a big benefit of using Struts is that you implement many proven Java EE design patterns without even knowing it. The Front Controller (ActionServlet and Action), View Helper (Action), Composite View (the Tiles framework that we’ll discuss later), Service to Worker (ActionServlet to actions), and Dispatcher View (ActionForward) are all integrated into the Struts framework.

Struts Home | All Struts Tutorials | Latest Struts Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.

Bookmark and Share


Be the first one to add a comment

Your name (required):

Your email(required, will not be shown to the public):

Your sites URL (optional):

Your comments:

More Tutorials by Fanny Ong
Signing a jar file example
instanceof operator example in Java
Origin and Architecture of Struts

More Tutorials in Struts
Configuring JDBC DataSources in Struts
Struts Classes
FAQ: Why was reload removed from Struts (since 1.1)?
FAQ: Why are my checkboxes not being set from ON to OFF?
Using JavaScript to submit a form in Struts
How to prepopulate a form in Struts
Simple example of using the requiredif Validator rule in Struts
Chaining actions in Struts
When is the best time to validate input in Struts
What is a Plug-in and how to use Java plug-ins with Struts?
7 Best Practices of Struts
Origin and Architecture of Struts
ActionErrors and ActionError in Struts
Tutorial on Struts Configuration File - struts-config.xml in Struts - from the book: Struts Survival Guide. Basics to Best Practices
Handling multiple buttons in HTML Form in Struts

More Latest News
Most Viewed Articles (in Struts )
Using Checkbox & Radio Tags, html:select, html:options in Struts Forms
Editing struts-config.xml in a Struts Application
MVC Architecture (Model 2 Architecture)
Use of {0} is required and Accessing resource bundles programmatically in Struts
ActionErrors and ActionError in Struts
Protecting JSPs from direct access in Struts
DispatchAction in Struts
XDoclet struts-config.xml in Struts
Struts-GUI and Struts Console
Origin and Architecture of Struts
What is Struts? Which Version of Struts to use?
Is Struts the most popular web application framework for Java?
What is a Model View Controller (MVC) Model?
History of Struts
WebWork 2 is now Apache Struts 2
Most Emailed Articles (in Struts)
History of Struts
What is a Model View Controller (MVC) Model?
The directories and files of a Struts application
Struts and Tiles - Steps to use Struts and Tiles
Creating Struts Modules
Handling Duplicate Form Submissions in Struts
Origin and Architecture of Struts
What is Struts? Which Version of Struts to use?
Is Struts the most popular web application framework for Java?
WebWork 2 is now Apache Struts 2
Struts Classes
Editing struts-config.xml in a Struts Application
Creating the first application using Struts 2
MVC Architecture (Model 2 Architecture)
Installing and configuring Tomcat and Struts