Struts 1
How Struts 1 is organised
Struts 1 is organised as a number of distinct elements that work together. These include:
- struts-config.xml. Each Struts application has a configuration file that specifies how the application works. This makes it very flexible to use since the application can often be changed by simply changing its configuration, rather than having to rewrite any code. However, it can also be very frustrating because there is often no simple way of checking the configuration for typing mistakes, and the error is only detected at runtime.
- ActionServlet. Each Struts application contains only one servlet. Normally you use the ActionServlet class that comes with Struts.
- ActionForm. An ActionForm represents the data that is contained on an HTML form submitted by the user. An ActionForm can either be a JavaBean extending the class org.apache.struts.action.ActionForm with appropriate properties, or you can use a DynaActionForm, which allows you to specify the properties in the struts-config.xml file. Typically you would implement one ActionForm for each different type of form your user was likely to submit.
- Action. An Action is what gets performed to deal with a specific HTTP request. It contains the code that would normally be found in a servlet. Typically you would implement one Action for each request-level function your application performs; each having a unique URL.
- ActionErrors. This is the object (or objects) that you use to contain any error messages produced by your application.
- ActionForward. An Action must return an ActionForward object, which is basically a signal to the ActionServlet as to what should happen next after an action is completed. Typically, an Action might return one ActionForward if it has executed successfully, and this will map on to a JSP page that displays the results. If errors have been detected in the user's input (or the Model has reported an error), then a different ActionForward should be returned that maps on to a different JSP page that displays the error messages.
- ActionMapping. The ActionMappings are the central configuration element of Struts. A mapping states what ActionForm is associated with a particular action, and also which Action should be called when a request is made to particular URL. It also specifies the next step to be taken upon return of a particular ActionForward. The ActionMapping (represented in the XML file, not in code) is thus the "junction box" of the application, deciding which components should be linked together.
- Struts taglib. Struts provides 5 JSP tag libraries. The three most commonly used ones (bean, html and logic) can together be used to develop very powerful JSP pages for your application's views. The tags integrate the View closely into the Controller (e.g. by making sure that the correct action is specified in a FORM).
The Struts 1 example application
Ted Husted's logon example
Webapp root / Zipped
Reading
Husted et al, chapters 1-3 and use chapters 5-10 as reference material when you come to use Struts.
Basham et al, chapter 14
Download Struts 1 and install the struts-documentation.war application in your own web server.
Masslight tutorial on Struts: Part 1 // Part 2