Struts - First Steps
(Web Tutorial)
by Michael Thomas
Struts Home Page
In this tutorial you will install Struts, test the install, view
the Struts docs and view some example Struts webapps.
Note: On the "Struts Home Page", you can download
the whole site (all content, tutorials & examples) !!!
This tutorial covers: Struts 2.0.11.1
running on Apache Tomcat
6.0.16 (as of 05/25/08)
Prerequisites
- Web App container that supports:
Servlet API 2.4 - (ie: Tomcat 5.x or higher)
JSP API 2.0 - (ie: Tomcat 5.x or higher)
Java 5
- Note: On the home page of "Free Web Tutorials on Java & Web
Technologies" we have a tutorial to install Java JDK & Tomcat.
- This tutorials has been tested in the following environment:
Date: 05/25/08
OS: Win XPro
JDK: jdk1.6.0_03
Objectives
- Install Struts
- Test your install
- View some example Struts webapps.
- View Tomcat's docs.
Download & Install Struts into Tomcat
- Goto:
http://apache.org/
- Click on the “Struts” project (right side of the page)
- On the first page under "Recent Releases"
(ie: 04 March 2008 - Struts 2.0.11.1 General Availability Release)
- Click on the link "Struts 2.0.11.1".
- Note: In the next section when you download the files just right
click on the link the choose "Save Target As".
- Under the section titled "Struts 2.0.11.1" download the
following:
- Full distribution: struts-2.0.11.1-all.zip (86mb) - this has all
of the above but you would have to split the data up.
- Essential Dependencies Only: struts-2.0.11.1-lib.zip (4mb) - this
is the library files needed for struts to work. These files are in the
full distribution.
- FYI Only - Do Not download
these files. These files are in the "Full Distribution".
- Example Applications: struts-2.0.11.1-apps.zip (22mb) - several
example web apps
- Documentation: struts-2.0.11.1-docs.zip (55mb) - Struts
documentation.
- Blank Application only: struts2-blank-2.0.11.war - this war is in the
examples & full distribution.
- Install the Struts Library files into Tomcat
- struts-2.0.11.1-lib.zip - copy this file to the Tomcat root
directory
Ex: C:\Program Files\Apache Software Foundation\Tomcat 6.0
- Extract the zip file maintaining the
file structure.
Note #1: To
use these files you will copy the ones you need into your web apps
"WEB-INF\lib" directory.
Note #2:
Instead, I like to start with the blank struts app called:
struts2-blank-2.0.11.war
In any case, I like to install the zip file here!
- Unzip the "Full Distribution" zip file
- For this tutorial, I suggest copying this file to the location below and
unzipping it (maintaining it's directory structure).
Copy this file: struts-2.0.11.1-all.zip
To: C:\java\apache\struts
Now, unzip it!
It should extract to: struts-2.0.11.1
(Note: However, you can place them anywhere you want for your
reference.)
- Struts Docs (installed from the "Full Distribution" zip file)
- Install the 4 Example Webapps
- Locate the Tomcat Webapps directory:
IE: C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps
- Copy the 4 .war files to the Tomcat Webapps directory from where you
extracted the files:
C:\java\apache\struts\struts-2.0.11.1\apps
- struts2-blank-2.0.11.1.war
- struts2-mailreader-2.0.11.1.war
- struts2-portlet-2.0.11.1.war
- struts2-showcase-2.0.11.1.war
- Make sure Tomcat is running.
http://localhost:8080 - if not, the
start the Tomcat service.
Start Tomcat: Control Panel, Administrative Tools, Services.
Right click on "Apache Tomcat", click "Start"
Test your Install
- Example web apps: (war = web application archive)
Finished.
- Finished - have a cup of java.
Other Notes
- Errors
- HTTP Status 503 - This application is not currently available.
Solution: Go to the Tomcat Manager and see if the web app is running.
Miscellaneous Notes
Struts Classic
Struts Shale Framework - leverages JavaServer Faces (JSF).
Struts Action Framework - original struts taglib leveraging JavaServer Pages (JSP).
JSTL - JavaServer Pages Standard Tag Library
JSFL - JavaServer Faces Tag Library
EL - Expression Language
Struts Subprojects (note: Classic Struts – I think has all
of the subprojects).
Applications
BSF Scripting
Core
EL
Flow
JSF Integration