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.2.1.1
running on Apache Tomcat
6.0.32 (as of 03/20/2011)
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.2.1.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 Struts's docs.
Download & Install Struts into Tomcat
- Goto:
http://apache.org/
- Click on "Download" in the Blue Menu bar located towards the top of the
page.
- Click on "Struts" in the "Projects" column.
Go to:
http://struts.apache.org/ (checked 03/20/11)
- On the first page under "Recent Releases". Look for the
"General Availability (GA) Release" (or "Ready for Primetime").
- 20 Dec 2010 - Struts 2.2.1.1 General Availability Release
struts-2.2.1.1-all.zip - (110mb)
- Other releases since this tutorial:
As of 03/21/2011 - none
- Click on the link "Struts 2.2.1.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.2.1.1" download the
following:
- Full distribution: struts-2.2.1.1-all.zip (110mb) - this has all
of the above but you would have to split the data up.
- FYI Only - Do Not download
these files. These files are in the "Full Distribution".
- Example Applications: struts-2.2.1.1-apps.zip (34mb) - several
example web apps
- Essential Dependencies Only: struts-2.2.1.1-lib.zip (11mb) - this
is the library files needed for struts to work.
- Documentation: struts-2.2.1.1-docs.zip (60mb) - Struts
documentation.
- Blank Application only: struts2-blank-2.2.1.1.war - this war is in the
examples & full distribution.
- FYI Only - download the source code is optional. It can
help when the documentation is lacking and you want to view the course code.
- Source: struts-2.2.1.1-src.zip (20mb) - Struts source.
- 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.2.1.1-all.zip
To: C:\java\apache\struts2
Now, unzip it!
It should extract to: C:\java\apache\struts2\struts-2.2.1.1
(Note: However, you can place them anywhere you want for your
reference.)
- Struts Docs (installed from the "Full Distribution" zip file)
- 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.2.1.1\apps
Ex To: C:\Tomcat\Tomcat6.0\webapps
- struts2-blank-2.2.1.1.war
- struts2-mailreader-2.2.1.1.war
- struts2-portlet-2.2.1.1.war
- struts2-rest-showcase-2.2.1.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"
- To use Struts in your webapp just copy the jar files you need from the
Struts lib directory (C:\java\apache\stuts2\struts-2.2.1.1\lib) into your
webapps "WEB-INF\lib" directory.
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