Origin and Architecture of Struts
By: Fanny Ong in Struts Tutorials on 2007-10-12
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
File upload and logging utilities
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.
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
- Your name, rating, website address, town, country, state and comment will be publicly displayed if entered.
- Aside from the data entered into these form fields, other stored data about your comment will include:
- Your IP address (not displayed)
- The time/date of your submission (displayed)
- Your email address will not be shared. It is collected for only two reasons:
- Administrative purposes, should a need to contact you arise.
- To inform you of new comments, should you subscribe to receive notifications.
- A cookie may be set on your computer. This is used to remember your inputs. It will expire by itself.
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
- Although the administrator will attempt to moderate comments, it is impossible for every comment to have been moderated at any given time.
- You acknowledge that all comments express the views and opinions of the original author and not those of the administrator.
- You agree not to post any material which is knowingly false, obscene, hateful, threatening, harassing or invasive of a person's privacy.
- The administrator has the right to edit, move or remove any comment for any reason and without notice.
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
- Data Science
- React Native
- Cloud Computing
- Java Beans
- Mac OS X
- Office 365
- Tech Reviews
Handling Duplicate Form Submissions in Struts
Guidelines for Struts Application Development
Configuring JDBC DataSources in Struts
FAQ: Why was reload removed from Struts (since 1.1)?
FAQ: Why are my checkboxes not being set from ON to OFF?
How to prepopulate a form in Struts
When is the best time to validate input in Struts
Simple example of using the requiredif Validator rule in Struts
What is a Plug-in and how to use Java plug-ins with Struts?