Struts 2 > Downloading and installing WebWork |
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:
[the tomcat root directory] \|_webapps \|_webwork-lessons \|_WEB-INF \|_classes \|_lib
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. |
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
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:
Read more: struts.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