J3 Limited
First Struts Project


In the previous section, the software required to develop a Struts web application was configured. In this section a very basic web project is created to ensure that everything is present and correct.

Create A Web Project

A new Dynamic Web Project is created, called StrutsProject:

new web project

new web project 2

new web project 3

The struts project properties is opened up.

The user library, created earlier, is added to the StrutsProject, and also setup to be part of the deployment:


The Struts.1.3 library is earmarked as being exported to dependent projects:


The Struts1.3 library is added as a Web Library dependency:

sproperties jee dependencies

A Struts project is typically composed of:

Mandatory files

  • web.xml, the JEE way of defining a web application.
  • struts-config.xml, the file that contains the relevant entries for the struts web application.
  • jsp pages to generate the web pages (view).
  • java classes to provide the functionality (model and controller classes).

Optional files

  • jar library files, for example data access layer components.
  • property files, for the text that is displayed.
  • type library descriptor files (Tld's), these files hold the syntax for custom jsp tag libraries.

Initial Files

A starter web.xml is shown below. This file was originally generated by Eclipse in the WebContent/WEB-INF folder. It is configured to load the Struts servlet:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

The struts action servlet is where all the page requests should go. It is told where to look for the struts-config.xml file, and the debug is set to level 3.

In the mapping, we inform the web container that any page request of the form *.do should be sent to the struts action servlet.

Finally, the default file is called index.jsp.

A starter struts-config.xml is created in the WebContent/WEB-INF folder:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"

<form-beans />
<global-exceptions />
<global-forwards />
<action-mappings />

A new JSP is created, called index.jsp in the WebContent folder:

create index.jsp

The contents of the file are as follows:


 This is index.jsp


First Test Run

In the project tree, the project is right clicked, and debug on server is selected. A dialog pops up:

first debug

The checkbox ("Always use this server when running this project") is clicked and finish is clicked.

The project runs and Eclipse navigates to the welcome page index.jsp:

run project

Running the project at this point is a good idea: it confirms that everything is configured correctly to run a Struts web application.

In the next section, a dynamic web page is developed using Struts.



  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.