Struts 2 - 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 - 2.1.8.1
running on Apache Tomcat
6.0.29 (as of 08/12/2010)
Prerequisites
- Struts 2 - 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 - (ie: Java 5 or higher)
- If you need help with the pre-requests go
to the home page of "Free Web Tutorials on Java & Web Technologies".
- This tutorials has been tested in the following environment:
Date: 08/12/2010,
OS: Win 7,
JDK: jdk1.6.0_21
Web Server: Apache Tomcat
6.0.29
Framework: Struts .2.1.8.1
(Older Tutorial -
Date: 05/25/08, OS: Win XPro, JDK: jdk1.6.0_03; Web
Server: Tomcat 5.5; Framework: Struts .1.2.8)
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: 16 November 2009 - Struts 2.1.8.1 General Availability Release)
- Click on the link "Struts 2.1.8.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.1.8.1" download the
following:
- Full distribution: struts-2.1.8.1-all.zip (116mb) - this has all
of the above but you would have to split the data up.
- Essential Dependencies Only: struts-2.1.8.1-lib.zip (11mb) - 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.1.8-1-apps.zip (34mb) - several
example web apps
- Documentation: struts-2.1.8-1-docs.zip (60mb) - Struts
documentation.
- Source: struts-2.1.8-1-src.zip (20mb) - Struts source.
- Blank Application only: struts2-blank-2.1.8-1.war - this war is in the
examples & full distribution.
- 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.1.8-1-all.zip
To: C:\java\apache\struts2
Now, unzip it!
It should extract to: C:\java\apache\struts2\struts-2.1.8-1
(Note: However, you can place them anywhere you want for your
reference.)
- Struts Docs (installed from the "Full Distribution" zip file)
- Install the Struts Library files into Tomcat
- struts-2.1.8-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!
- Install the 5 Example Webapps into Tomcat
- Locate the Tomcat Webapps directory: (Depending on how you
installed it.)
Example Location 1: C:\Tomcat\Tomcat6.0\webapps
Example Location 2: C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps
- Copy the 5 WAR files from the extracted directory to the Tomcat Webapps directory:
Ex From: C:\java\apache\struts\struts-2.1.8.1\apps
Ex To: C:\Tomcat\Tomcat6.0\webapps
- struts2-blank-2.1.8.1.war
- struts2-mailreader-2.1.8.1.war
- struts2-portlet-2.1.8.1.war
- struts2-rest-showcase-2.1.8.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)
Resources
- View Documentaion
- Tutorials - Struts
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