Struts 2 > Downloading and installing WebWork
Added by victorsosa, last edited by Ted Husted on Sep 03, 2006  (view change)

For this lesson, you need to have a Servlet container set up and know how to create a web application. If you don't, we suggest you learn about Apache Tomcat, which is a free Servlet container from the Apache Jakarta Project, or Resin, from Caucho Technology, which is free for noncommercial use.

Notation

Throughout these lessons, we'll assume that your web application root is the directory [webapp], and that your Java source files are kept in [src].

To install WebWork in a web application:

  1. Download WebWork. The current version can be found at WebWork's home page. This tutorial is based on version 2.2
  2. Set up an empty web application. For example, if you are using Tomcat, this will have something like the following directories (the directory "webwork-lessons" is referred to as [webapp] in these lessons):
    [the tomcat root directory]
    \|_webapps
      \|_webwork-lessons
        \|_WEB-INF
          \|_classes
          \|_lib
  3. Copy the required WebWork libraries to your web application:
  • copy webwork-2.2.jar to [webapp]/WEB-INF/lib ,
  • copy lib/*.jar to [webapp]/WEB-INF/lib.
  1. Configure [webapp]/WEB-INF/web.xml, and create [webapp]/WEB-INF/classes/xwork.xml and [webapp]/WEB-INF/classes/validators.xml, as described below.

This is the bare minimum required to begin building the sample applications

Filename Description
xwork.jar XWork library on which WebWork is built
oscore.jar OSCore, a general-utility library from OpenSymphony
ongl.jar Object Graph Navigation Language (OGNL), the expression language used
throughout WebWork
velocity-dep.jar Velocity library with dependencies
commons-logging.jar Commons logging, which WebWork uses to support transparently logging to
either Log4J or JDK 1.4+
javamail by sun for mail
rife-continuations by rife for continuations feature
web.xml J2EE web application configuration file that defines the servlets, JSP tag
libraries, and so on for your web application
xwork.xml WebWork configuration file that defines the actions, results, and interceptors
for your application
WebWork jar name

If you have a later version of WebWork than 2.1.7, the WebWork jar will not be named webwork-2.2.jar. Be sure to replace all occurrences of this jar's name below with the name of the jar you are using.

web.xml:

Create the following web.xml file in [webapp]/WEB-INF. If you already have a web.xml file, just add the content of the <web-app> tag below to your existing <web-app> tag.

<?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 WebWork Application</display-name>
	<servlet>
		<servlet-name>webwork</servlet-name>
		<servlet-class>com.opensymphony.webwork.dispatcher.ServletDispatcher</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>webwork</servlet-name>
		<url-pattern>*.action</url-pattern>
	</servlet-mapping>
	<taglib>
		<taglib-uri>webwork</taglib-uri>
		<taglib-location>/WEB-INF/lib/webwork-2.2.jar</taglib-location>
	</taglib>
</web-app>

This registers ServletDispatcher as a servlet, and maps it to the suffix *.action.

Read more: web.xml

xwork.xml:

Create the following file xwork.xml in [webapp]/WEB-INF/classes/.

<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN" 
"http://www.opensymphony.com/xwork/xwork-1.0.dtd">

<xwork>
	<!-- Include webwork defaults (from WebWork JAR). -->
	<include file="webwork-default.xml" />
	
	<!-- Configuration for the default package. -->
	<package name="default" extends="webwork-default">
	</package>
</xwork>

For now, this xwork.xml does only two things:

  • It informs WebWork that it should import the configuration information from webwork-default.xml. (This file is located at the root of the webwork-2.2.jar, so it is sure to be found.)
  • It defines a default package (with the <package> section) where WebWork elements like actions, results and interceptors are registered.

Read more: struts.xml

validators.xml:

Create a file validators.xml in [webapp]/WEB-INF/classes/ with the following content:

<validators> 
	<validator name="required"
		class="com.opensymphony.xwork.validator.validators.RequiredFieldValidator"/> 
	<validator name="requiredstring"
		class="com.opensymphony.xwork.validator.validators.RequiredStringValidator"/> 
	<validator name="int"
		class="com.opensymphony.xwork.validator.validators.IntRangeFieldValidator"/> 
	<validator name="date"
		class="com.opensymphony.xwork.validator.validators.DateRangeFieldValidator"/> 
	<validator name="expression"
		class="com.opensymphony.xwork.validator.validators.ExpressionValidator"/> 
	<validator name="fieldexpression"
		class="com.opensymphony.xwork.validator.validators.FieldExpressionValidator"/> 
	<validator name="email"
		class="com.opensymphony.xwork.validator.validators.EmailValidator"/> 
	<validator name="url"
		class="com.opensymphony.xwork.validator.validators.URLValidator"/> 
	<validator name="visitor"
		class="com.opensymphony.xwork.validator.validators.VisitorFieldValidator"/> 
	<validator name="conversion"
		class="com.opensymphony.xwork.validator.validators.ConversionErrorFieldValidator"/> 
</validators>

This file defines the validators used, for example, for validating html form fields.

Read more: Validation


Next Lesson