How do I set up a Struts 1 project?
Author: Deron Eriksson
Description: This Java tutorial walks through setting up a Struts 1 project in Eclipse.
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 1.5.1 || Tomcat 5.5.20

Page:    1 2 3 >

ApacheSW StrutsW is a framework for creating Model-View-Controller-based JavaSW web applications. Struts exists in two versions, Struts 1 and Struts 2. This tutorial will cover Struts 1. To begin with, you can download the Struts libraries, documentation, source code, and sample applications from

For this tutorial, I downloaded the file. We find the following jarW libraries within this zip file.

Struts jar libraries

Not all of the above libraries are necessary to use the basic functionality of Struts. One way to figure out which jar files are needed is to set up a project, start the project, and include required jar files until all the errors (many of which are runtime) disappear when you run the application. If we follow this technique, we find that for this tutorial, commons-beanutils-1.7.0.jar, commons-chain-1.1.jar, commons-digester-1.6.jar, struts-core-1.3.5.jar, and struts-taglib-1.3.5.jar are the required jar files.

Our struts-demo project is shown below, with the required jar files added to the /lib directory. These jar files are added to the build path of the project.

jars added to lib directory

Next, I'll describe the various files in the project and how they all fit together. The best place to start is the web.xmlW file. First off, notice that we utilize the Struts ActionServlet. This servletW serves as our controller, which means that this servlet decides where to send the browser when it makes a request of our application. Notice that the 'config' init parameter points to '/WEB-INF/struts-config.xml', which contains the various Struts mappings and things, which we'll describe soon. The ActionServlet is configured to start up when our application starts up (rather than the first time the servlet is hit).

Notice that requests made to our application ending with '.do' map to the ActionServlet. In Struts, a particular '.do' maps to a particular Action to perform. So, if a particular URL is hit (which may or may not include parameters), the ActionServlet decides where to send the request to the application.

Finally, notice that index.jsp is a welcome file. So, if we hit our application, the default page that is hit is index.jsp.


<?xml version="1.0" encoding="UTF-8"?>
<web-app id="struts-demo" version="2.4"
	<display-name>Struts Demo</display-name>

Next let's examine index.jsp. The top of the JSPW has 4 Struts taglibs referenced, although only one is actually needed. The logic:redirect tag instructs our application to be forwarded to 'howdy'. Where does this 'howdy' go?


<%@ taglib uri="" prefix="bean"%>
<%@ taglib uri="" prefix="html"%>
<%@ taglib uri="" prefix="logic"%>
<%@ taglib uri="" prefix="nested"%>
<logic:redirect forward="howdy"/>

The last question is answered by examining our struts-config.xml file. This file contains a global-forwards section, which contains 'forward' mappings that can be used throughout our application. In this section, we can see that 'howdy' maps to the '' Action. Notice that this file contains an action-mappings section, and one of the actions in this section is 'myStart', which forwards a request to the 'start.jsp'. Although this may seem a little confusing at first, this means that if we make a request to index.jsp, the request will get forwarded to 'howdy', which maps to '', which maps to the 'start.jsp'.


<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
		<forward name="howdy" path="/" />
		<action path="/myStart" forward="/start.jsp" />
		<action path="/myTest" type="test.TestAction">
			<forward name="success" path="/success.jsp"/>
			<forward name="failure" path="/failure.jsp"/>
	<message-resources parameter="StrutsDemoResources" />

(Continued on page 2)

Page:    1 2 3 >