J3 Limited
 
Google
WWW J3Ltd
 
Struts

Introduction

Struts is a "Model View Container" (also known as MVC) framework used to write java based web applications. Other MVC frameworks include:

  • JSF
  • Struts 2
  • Spring MVC

Currently Struts version 1 is an extremely popular MVC framework in terms of usage. This article gives a quick overview of how a web application can be developed using Struts 1.

Downloading Struts

Struts 1 (and Struts 2) can be downloaded from http://struts.apache.org/

Once downloaded, the zip archive contains the files that are necessary to deploy Struts to a Servlet container. In this article Tomcat 6 is used as the servlet container (see http://jakarta.apache.org).

Struts Distributions

There are a few Struts versions, 1.1, 1.2 and 1.3. Version 1.3.8 is probably the last "General Availability" version 1 release.

A brief comparison of the distributions is worth a visit in order to appreciate some of the slight differences that exist.

Struts 1 Jar Files (typically deployed in the web-inf/lib folder)
File name 1.1 1.2 1.3 Notes
antlr.jar   X X Used by the validator (validwhen validator)
bsf.jar     X Allows scripting engines to call on Java classes and vice-versa
commons-beanutils.jar X X X Utilities to simplify access to Java Beans (no need to write reflection code)
commons-chain.jar     X Chain of Responsibility pattern
commons-collections.jar X     Collection utilities. When using a JDK of 1.2 or later, the Java API is preferred
commons-digester.jar X X X XML to Java configuration utilities
commons-fileupload.jar X X X Allows file upload facilities to be added to Web applications
commons-io.jar     X I/O utilities
commons-lang.jar X     Functionality for java.lang (String, numerical, reflection)
commons-logging.jar X X X Wrapper for logging implementations
commons-validator.jar X X X validator framework: validation rules are defined in XML Validation methods are provided
jakarta-oro.jar X X   Text processing utilities (awk, perl... expression evaluators and tools)
jstl.jar     X JSP Standard Tag Library
oro.jar     X Text processing utilities
standard.jar     X Apache JSTL classes and Tld files (JTSL version 1.0)
struts.jar X X   Complete Struts implementation
struts-core.jar     X Core of the Struts implementation
struts-el.jar     X Struts tags and tag library descriptors
struts-extras.jar     X Additional functionality such as DispatchAction, LocaleAction....
struts-faces.jar     X Support for JSF
struts-legacy.jar X     GenericConnection and GenericDatasource for JDBC connections
struts-mailreader-dao.jar     X This looks like it should be in the Struts samples (app's) not lib
struts-scripting.jar     X Allows actions to be written in scripting languages rather than Java classes
struts-taglib.jar     X Struts tag library descriptors and implementation classes
struts-tiles.jar     X Tiles support

 

Struts 1 Tld's (typically deployed in the web-inf folder)
File name 1.1 1.2 Description
struts-bean.tld X X Much of this can be accomplished using JSTL
struts-html.tld X X Html form element, image, hyperlink tags
struts-logic.tld X X Much of this can be accomplished using JSTL
struts-nested.tld X X Allows tags to be nested within one another. Provides implementations of the Bean, Logic, HTML tags
struts-template.tld X   Tags useful when dynamic JSP templates are needed. Note that the Tiles framework also does this.
struts-tiles.tld X X Used to specify the layout of all the JSP's within the web application.
validator-rules.xml X X Defines all the validation rules that are available. validation.xml is used to map rules to ActionForm classes

In Struts 1.3, the Struts TLD files are stored in struts-taglib.jar. The JSTL TLD files are in standard.jar. Looking at the contents of the TLD files is important for two reasons:

  • It provides the "uri" element that can be used in JSP's
  • It gives the version number of the tag library.

By looking at the TLD files in standard.jar, the version of JSTL, that is distributed with Struts 1.3, is found to be 1.0.

Distributions Used

In this article the following software packages are used:

Software Used
Software Description
Java JDK 6 SE The Java runtime and sdk used
Eclipse 3.4 For Java EE Java IDE configured to use the JDK and Tomcat downloaded
Struts 1.3.8 The Struts API used
Tomcat 6 The Servlet container used

The order in which the software packages are installed is somewhat important (the JDK should be installed first).

Installation Notes (Windows)

JDK

The JDK is installed by running the downloaded file.

Eclipse

Eclipse is downloaded as a compressed archive. The installation process involves extracting the contents of the archive, the eclipse.exe executable is the program to run the IDE.

Struts

Struts is downloaded as a compressed archive. The archive contains sample applications, documentation, the source code and a lib folder which contains the Struts jar files that should part of every Struts project.

Tomcat

Tomcat version 6 is used in this article. Tomcat 6 implements the following specifications:

  • Servlet 2.5
  • JSP 2.1

Tomcat can be downloaded as an archive or a windows service installer. On the Tomcat Download page, there is also a Tomcat Web Application Deployer. The Web Application Deployer is not needed for this article.

When downloading the Windows Service Installer, care must be taken, as it can cause tomcat to be installed as a Windows Service: the service starts up Tomcat when the PC is booted up. For development purposes, Tomcat is started and stopped from Eclipse.

When downloading the archive, it is extracted. Within the extracted bin folder, startup.bat can be executed to launch Tomcat, shutdown.bat to shutdown Tomcat. It is worth noting that the environment variable JAVA_HOME needs to exist to Tomcat to run successfully using startup.bat. JAVA_HOME points to where the JDK has been installed (for example JAVA_HOME=C:\Program Files\Java\jdk1.6.0_02).

Configuring Eclipse

The Eclipse executable is run. Once loaded, the Window menu's Preferences dialog is opened.

The default JRE is configured to point to the JDK, as some functionality is only available in the JDK:

Tomcat is configured in Eclipse:

The JRE used to run tomcat is also setup, using the JDK previously configured in Eclipse:

A Libraries Project

Eclipse facilitates the creation of user libraries. When projects use several open source components, creating a library for each one is usually a good idea.

In this section a user library for Struts 1.3 is created.

From the File menu, a new project is created, called Libraries:

Once created, a folder called Struts_1_3 is created. The struts 1.3 files are copied from the file explorer into the eclipse project.

The Window menu's Preferences dialog is opened up to create a user library for Struts1.3:

The Struts jar files are added to the user library (those that have been copied to the libraries project):

In the next section, a Struts project is created.

 

  Copyright © 2006 J3 Ltd Permission is granted to reproduce material on this page, on the condition that a reference to "WWW.J3Ltd.com" is given as the source of the material.