How to Build Applications
This document outlines one possible sequence of development steps that can be followed to create a Struts application. It is not intended as a complete description of each referenced development activity. More detailed documentation is available elsewhere and is referenced by "(more...)" links where possible.
For those who are short on time and/or patience, you can get a Struts application up and running in a matter of minutes thanks to Maven's archetype feature.
NOTE - as of the time of this writing (10/16/2006), the specified version in this example has not been released. Once this has been released, this note can be removed and the archetype will work fine.
$ cd ~/projects
$ mvn archetype:create \
-DarchetypeGroupId=org.apache.struts \
-DarchetypeArtifactId=struts-archetype-blank \
-DarchetypeVersion=1.3.5 \
-DgroupId=com.example \
-DpackageName=com.example.projectname \
-DartifactId=my-webapp
$ cd my-webapp
$ mvn install
$ mvn jetty:run
Caveats
- Requirements development and design are outside of the scope of this document.
- For help installing the framework, see the Getting Started chapter.
- There are many other ways to approach development with the framework and there are many other features available besides the ones discussed below. This document outlines only one way to get started.
- This document focuses on form/data centric applications, but may also work with other types of applications.
- This material was originally written for Struts 1.1 (beta 2), and reviewed for the 1.3.5 distribution.
Overview
- Implement data entry forms as JSP files.
- Implement one or more
ActionFormdescendents to buffer data between JSPs and Actions. - Create an XML document that defines the validation rules for your application.
- Implement one or more
Actiondescendents to respond form submissions. - Create
struts-config.xmlto associate forms with actions. - Create or update
web.xmlto referenceActionServlet. - Parallel Tasks
- Building
- Unit Testing
- Deployment
Details
- Implement data entry forms as JSP files.
- Use elements from the
htmltaglib to define the form elements. (more...) - Use
messageand other elements from thebeantaglib to define the labels and other static text of the form. (more...)- Create and maintain a properties file of the text elements to be displayed. (more...)
- Use
propertyattributes to link form fields toActionForminstance variables.
- Use elements from the
- Implement one or more
ActionFormdescendents to buffer data between JSPs and Actions.- Create get/set pairs that correspond to the
property names
in your related JSP form. Example:
needs:
<html:text property="city" />
getCity() and setCity(String c)
- When needed, create a
resetmethod that sets the fields of theActionFormto their default values. Most ActionForms do not need to do this.
- Create get/set pairs that correspond to the
property names
in your related JSP form. Example:
- Create an XML document that defines the validation rules for your application.
- Implement one or more
Actiondescendents to respond to form submissions.- Descend from DispatchAction or LookupDispatchAction if you want one class to handle more than one kind of event (example: one Action to handle 'insert', 'update' and 'delete' events, using a different "surrogate" execute method for each). (more...)
- Use the
executemethod (or its surrogates) of your Action class to interface with objects in your application responsible for database interaction, such as EJBs, etc. - Use the return value of the
executemethod (or its surrogates) direct the user interface to the appropriate next page.
- Create
struts-config.xmlto associate forms with actions. The file minimally needs: - Create or update
web.xmlto referenceActionServlet(more...) - Parallel Tasks
- Building
- Use Ant. It can compile, create WAR file, perform XSLT transformations, run unit tests, interact with version control systems, clean up, etc. (more...)
- Create and use build script incrementally, as you create files that need to be copied, compiled, etc.
- Unit Testing
- Unit test normal JavaBeans with JUnit. (more...)
- Unit test JSP, taglibs, and conventional servlet components with Cactus. (more...)
- Unit test Action servlets with StrutsTestCase. (more...)
- Add all unit tests to the build script
as a separate
target. This target should use the
junittag to launch each TestCase descendent. (more...)
- Deployment
- Build script should create a WAR file containing the files developed above, along with files that make up the framework.
- Building


