...
Struts Action Framework 2 is a popular, easy-to-use MVC framework. For more information on the SAF project, please visit the SAF Project Home.
This document This tutorial will help you to get started with the framework, enabling you to run the examples and demonstrations provided even if you are not an experienced Java web application developer. NeverthelessThe tutorial will walk you through installing the framework and creating a simple application.
However, the framework is geared towards developers that have an understanding towards certain technologies.Before diving deeper into how the SAF works, it is recommended that you have some knowledge of the supporting technologiestoward professional developers. To create non-trivial applications, a working knowledge of several key technologies is required.
Panel | ||
---|---|---|
| ||
|
For more about any of the supporting technologies, visit the Key Technologies page on the Apache Struts website.
...
To get started with In this lesson, we download the framework, download launch the distribution and browse some of the online resourcesexample applications, and then get started on an application of our own.
Download the Distribution
Note |
---|
A release of SAF 2 may not yet be available. |
The full distribution can be downloaded form the Apache Struts website. The distribution contains the struts-action2.jar
file, a copy of all the documentation, sources, all required and optional dependencies,and example applications. For more information on how to build the framework from source or even from a clean checkout, please refer to Building the Framework from Source.
Browse the Resources
There are many online resources available. Here are links to help you find your way:
- Download SAF2 - download the framework distribution
- Join the Forums - The forums are full of active developers, contributors, and power users - often even available for chat. This is the best and quickest way to get a question answered.
- Subscribe to Mailing List and post a question, or browse Mail Archive. (You probably want to browse the archive or forum first. All posts from the forum are posted to the mailing lists, and vice versa.
- Subversion Repository - Browse the source.
- Confluence Wiki - Read it here first! The project documentation is created on the wiki and then posted as HTML to the website.
- JIRA Issue Tracker - Browse or file enhancements requests and defect reports.
- Apache Struts Home
Distribution Quickstart
...
The distribution contains the following directory layout:
...
The framework also comes packaged with all the source files and templates for the JSP tags.
Running
...
the Examples
Several example applications come bundled with the distribution. You can run these using the QuickStart feature or in your own web container.
Running with QuickStart
...
The framework provides a slick way to jump into web development called QuickStart. Essentally, QuickStart is combination of technologies and conventions. The key technology is the ability to run web applications "out of the box" with a stripped-down Jetty container.
...
You can review the QuickStart documentation to learn more about how it works and how you can utilize QuickStart with your own applications.
...
In order to deploy applications and demos to your favorite servlet container (also called web container) such as Apache Tomcat or Caucho Resin, you will need to build WAR files from the webapps directory. You will find an Antbuild file there which will provide you with an easy way to build your own WARs.
Note | ||
---|---|---|
| ||
Quickstart is a handy tool for development of your applications. We recommend that you give QuickStart a try, to see if it meets your development needs. However, QuickStart is not meant to be your sole environment for web application development. QuickStart is meant to help you rapidily create proof-of-concepts and so that you can see the result. We recommend you always at least test your work under other applications servers, such as Tomcat, Resin, or even the standard, standalone version of Jetty. |
Running with your web container
In order to deploy applications and demos to your favorite servlet container (also called web container) such as Apache Tomcat or Caucho Resin, you will need to build WAR files from the webapps directory. You will find an Antbuild file there which will provide you with an easy way to build your own WARs.
To build a web application archive (WAR), simply run:
...
Info | ||
---|---|---|
| ||
The framework build copies the sources of each bundled web application to |
Your First SAF2 Application
...
To get started on your own application, you can utilize the blank template, run the Ant task, or just setup your own from scratch.
...
The Ant buildfile will prompt you for a the name of your new application.
Setting up from
...
scratch
If for some reason the blank template doesn't work for you, it's not so hard to setup a SAF-based application from scratch.
...
- Copy to your
webapp/lib
directory- the
struts-action-(VERSION).jar
, - all the
*.jar
files in/lib/default
, - and any necessary optional {{
*.jar
} files in {{/lib/(optional configuration) }}.
- the
If you need to customize your own templates (how HTML is rendered from webwork UI tags), copy into your
webapp/
directory the /src/java/template
directory.
Minimum
...
set of
...
libraries and
...
configuration files
The following files are a minium requirement for your application.
Filename | Description |
---|---|
| Framework library itself, found in distribution root directory |
| XWork library on which WebWork SAF 2 is built |
| OSCore, a general-utility library from OpenSymphony |
| Object Graph Navigation Language (OGNL), the expression language used throughout the framework |
| Commons logging, which WebWork the framework uses to support transparently logging to either Log4J or JDK 1.4+ |
| All UI tag templates are written in Freemarker, which is also a good option for your views |
| The default dependency injection container for the framework. |
| J2EE web application configuration file that defines the servlets, JSP tag |
| WebWork Framework configuration file that defines the actions, results, and interceptors for your application |
...
Code Block | ||
---|---|---|
| ||
<?xml version="1.0"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>My Application</display-name> <filter> <filter-name>action2</filter-name> <filter-class>org.apache.struts.action2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>action</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app> |
The standard {{web.xml
} registers a FilterDispatcher to enable framework functionality for your requests. The ContextLoaderListener set ups configures Spring as our dependency injection conitainer. The framework uses Spring internally, and you may wish to use it to deploy your own objects.
See also: web.xml
Setup action.xml
Create a skeleton {\[ Wiki Markup action.xml
}} file in {{/$APP/WEB-INF/classes
/}}.
Code Block | ||
---|---|---|
| ||
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.1.1//EN" "http://www.opensymphony.com/xwork/xwork-1.1.1.dtd"> <xwork> <!-- Include framework defaults (from Struts Action JAR). --> <include file="action-default.xml" /> <!-- Configuration for the default package. --> <package name="default" extends="action-default"> </package> </xwork> |
...