[ Team LiB ] Previous Section Next Section

Setting Up Struts

After you have downloaded Struts, the first thing you need to do is make sure your webapp is set up to use Struts. To do this, you need to make sure the struts.jar is in your classpath. Typically, you would copy the struts.jar file under your WEB-INF\lib directory that will become part of the JAR file you will use to deploy your Web application.

The various other Struts JAR files that start with common*.jar should also be copied with the struts.jar file. All the Struts properties files will be under the WEB-INF directory.

If you have multiple Struts applications, you can copy these JAR files to the shared\lib or common\lib directories beneath your Tomcat installation home. Doing this allows all your webapps to use the same version of Struts. There are many arguments for and against this approach, but you do not need to worry about these for now.

The Struts download also comes with an empty Struts application called struts-blank.war. You can deploy this Web application to the webapps directory of Tomcat, and you can use it as a starting point for building a Struts application. Table 21.1 explains the directory structure of a Struts application.

Table 21.1. Directory Structure of a Struts Application

File or Directory

Purpose

META-INF

Meta information.

WEB-INF/classes

You should put all your Java classes here.

WEB-INF/classes/

This file contains all the messages,

ApplicationResources.properties

text, and error messages. Similar concept to internationalization.

WEB-INF/lib/struts.jar

This is the Struts library.

WEB-INF/*.tld

The Struts tag libraries.

WEB-INF/struts-config.xml

Struts configuration file.

WEB-INF/web.xml

Standard J2EE Web app configuration file.

index.jsp

Place all your jsp/html pages in the root of the Web app directory.

You now know how to create and deploy a simple Struts-based application. Now let's talk about JavaServer Faces (JSF) and how it relates to Struts.

    [ Team LiB ] Previous Section Next Section