Section 2: Installing & Configuring Struts

Installing Struts; Setting Up Struts Applications

Alert: the HTML version of this tutorial is no longer being actively maintained, and still covers Struts 1.1. For additional topics, updates for Struts 1.2, and complete source code, please see Introduction to Jakarta Struts (in PDF).

2.1 Downloading & Configuring Struts 2.2 Testing Struts
2.3 Setting Up Struts Applications 2.4 Accessing Struts Documentation
2.5 Adding Struts to an Existing Web Application
Struts Tutorial Table of Contents More Info

This section shows you how to download and set up the Apache Struts software.

2.1 Downloading and Configuring Struts

  1. Download the Struts zip file.
    Start at, or follow the link from I'm using Struts 1.1 in this tutorial.
  2. Unzip into a directory of your choice.
    For example, unzip into C:\jakarta-struts-1.1. Throughout the rest of this tutorial, I'll refer to this location as struts_install_dir.
  3. Update your CLASSPATH.
    Add struts_install_dir/lib/struts.jar to the CLASSPATH used by your compiler or IDE (not your server). Here are three possible ways of setting it:
    • Set it in your autoexec.bat file. E.g., on Windows if you unzipped into C:\jakarta-struts-1.1, you would add the following to C:\autoexec.bat:
      set CLASSPATH=C:\jakarta-struts-1.1\lib\struts.jar;%CLASSPATH%
      On Unix/Linux, use your .cshrc, .bashrc, or .profile instead.
    • Set it using the system settings. On WinXP, go to the Start menu and select Control Panel, then System, then the Advanced tab, then the Environment Variables button. On Win2K/WinNT, go to the Start menu and select Settings, then Control Panel, then System, then Environment. Either way, enter the CLASSPATH value from the previous bullet.
    • Set it in your editor or IDE. Most IDEs have a way of specifying the JAR files needed to compile projects. Or, you could make a small .bat file (Windows) or shell script (Unix/Linux) that supplies the struts.jar file as the argument to -classpath for javac.
  4. Install an XML parser.
    If you have JDK 1.4 or Apache Tomcat, this step is not necessary, since they already come with an XML parser. But, if you use JDK 1.2 or 1.3 with another server, you might need to obtain the XML parsing libraries. Here are two good sources:

2.2 Testing Struts

  1. Install struts-blank.war.
    Install the Web application from struts_install_dir/webapps/struts-blank.war on your server. For example, with Apache Tomcat, copy struts_install_dir/webapps/struts-blank.war to tomcat_install_dir/webapps/.
  2. Start or restart the server.
    Most servers only recognize new Web apps when the server is started.
  3. Access http://localhost/struts-blank/.
    This URL assumes you are running the server on your desktop and are using port 80. In general, access http://hostname:port/struts-blank/. You should see something like the following.

    Struts Blank

2.3 Setting Up Struts Applications

To make your own Struts application, you need to create a Web application that has the appropriate JAR files, TLD files, and web.xml entries. You almost always do this by starting with the struts-blank application and modifying it. You have three options for doing this:

2.4 Accessing Struts Documentation

You probably already have bookmarked the APIs for standard Java, servlets, and JSP. But you will also want to frequently refer to the Apache Struts documentation. You can do this two ways:

2.5 Adding Struts to an Existing Web Application

By far the easiest way to develop a Struts application is to start with struts-blank, rename it, and work from there. If that approach is an option for you, do it that way and skip this section. However, if you already have an existing Web application and want to add Struts capabilities to it, starting with struts-blank won't work. Adding Struts capabilities to existing Web apps is a huge pain in the neck, and will proably require several attempts to get it right. Here is a quick summary:

Next section: Processing Requests with Action Objects

More Information

J2EE Short Courses
Personally developed and taught by the author of Core Servlets & JSP, More Servlets & JSP, and this Jakarta Struts tutorial.
Contact Marty
Send email to to report errors and omissions in this writeup, or to inquire about training courses on Struts, JSP, servlets, JSF, AJAX, or Java 5 programming.
Jakarta Struts Books
Servlet & JSP Books