Getting Started with Apache Struts

Tutorial - Apache Struts 2 - From Soup to Nuts


Apache Struts 2 simplifies enterprise-ready web development by providing a flexible set of custom tags and an extensible application architecture. The framework is designed for professional developers creating sophisticated web applications that integrate with databases and other enterprise services. Originally known as WebWork, Struts 2 has been continuously maintained since March 2002, and most recently updated with the April 2012 release (2.3.3). Struts 2 is product of the Apache Software Foundation and distributed to the general public at no charge under the business-friendly Apache Software License 2.0. The ASF provides product support only through a public mailing list frequented by volunteer developers and users.

Getting Started

Struts 2 is directly supported by the three most popular integrated development environments (IDEs) for Java: IntelliJ IDEA by JetBrains, MyEclipse by Genutec, and NetBeans. For example, to create a Struts 2 application in IntelliJ IDEA, you can select the Struts 2 facet, and the IDE will download the JARs and setup a Java web application structure, ready for you to add your own pages and other Struts 2 elements.  

Figure 1 - IntelliJ IDEA ready for your Struts 2 elements

IntelliJ IDEA’s support for Struts 2 includes configuration via dedicated Struts 2 facet – with fileset manager, library validator, and configuration detector, dedicated Struts 2 structure tool windows, code inspectors that spot Struts 2-specific code issues, support for inplace Javascript and CSS code, smart coding completion within Struts elements, Struts 2-ready refactorings, and Struts 2-aware project navigation across Java, JSP and XML files. 

Likewise, with MyEclipse, you can add Struts 2 capabilities to a web project, including wizards to create new Struts 2 elements or edit existing elements. The wizards are context-sensitive and provide input assistance and validation as you edit Struts 2 elements. Not to be left behind, NetBeans offers its own set of wizards to create an example Struts 2 application, register the necessary library files, and then edit the various Struts 2 elements. In addition, NetBeans supports hyperlinking and code completion in Struts 2 configuration files. Struts 2 also provides a Maven prototype you can use to bootstrap a project, if you are so inclined, and, of course, the distribution has all the usual assets for hardcore hand-coders.

In Brief – The Elements of Struts Design

A dynamic Struts 2 application has seven building blocks:

  1. Pages with Struts Tags
  2. Message Properties
  3. Actions
  4. Interceptors
  5. Validators
  6. Results
  7. Annotations and Deployment Descriptors

 The elements can be organized into three groups:

  • Pages and Message Properties are used to create the application user interface.
  • Actions, Interceptors, and Validators process an incoming request, in order to render a page, or some other Result.
  • Annotations and Deployment Descriptors are used to define the initial state for the other elements of a Struts 2 application.

 Let’s take a look at each element in turn...



Ted Husted
Ted Husted

What do you think?

JAX Magazine - 2014 - 06 Exclucively for iPad users JAX Magazine on Android


Latest opinions