Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
/tutorial/
/tutorial/META-INF/
/tutorial/WEB-INF/
/tutorial/WEB-INF/classes/
/tutorial/WEB-INF/lib/
/tutorial/WEB-INF/lib/struts2-core.jar, xwork2.jar, freemarker.jar, ognl.jar, *plugin.jarminimum JARs + any plugin JARs + plugin dependencies
/tutorial/WEB-INF/web.xml
  • Copy to your webapp/lib directory
    • the struts2-core-(VERSION).jar,
    • all the *.jar files in /lib/default, and
    • required JARs (see next section),
    • any Struts plugin JARs,
    • any plugin dependenckies.any necessary optional *.jar files from /lib/.
Tip

To customize the Struts templates (how HTML is rendered from the tags), copy into the application's webapp directory the framework's /src/java/template directory.

...

Filename

Description

struts2-core.jar

Framework library itself, found in distribution root directory

struts2-api.jar

Framework API library, found in distribution root directory

struts2-spring-plugin.jar

The Struts Spring plugin, providing Spring integration classes

xwork2xwork.jar

XWork 2 library on which Struts 2 is built (version 2.0 or later)

ognl.jar

Object Graph Navigation Language (OGNL), the expression language used throughout the framework

commons-logging.jar

Commons logging, which the framework uses to support transparently logging to either Log4J or JDK 1.4+

freemarker.jar

All UI tag templates are written in Freemarker (also a good option for your own views)

spring*commons-logging.jar

The default dependency injection container for the framework. Commons logging, which the framework uses to support transparently logging to either Log4J or JDK 1.4+

web.xml

Java web application configuration file that defines the filters (and other components) for your web application

struts.xml

Framework configuration file that defines the actions, results, and interceptors for your application

applicationContext.xml

Spring configuration file for any application Spring beans (may be empty).

The library files (*.jar) needs to be copied to your /WEB-INF/lib/ directory. If you need optional functionalities requiring dependencies on optional JARs, those JARs need to be copied to this directory tooIf any Struts 2 Plugins are included, then other JARs may be needed too. For example, the optional Spring Plugin requires the Spring JARs to be present.

Setup the Web Application Deployment Descriptor (web.xml)

...

Code Block
titleweb.xml
<?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>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>struts2</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 configures Spring as our dependency injection container. The framework, when used with the Spring plugin, uses Spring to build many internal objects. (You may wish to use Spring to deploy your own objects too.)

If other packages are being used, like SiteMesh or Spring, then other filters may need to be configured too

(lightbulb) See also: web.xml

Setup the Struts Configuration (struts.xml)

...