1、下载和WebWork的安装
(1)本教程基于WebWork 2.1版本,在webwork.dev.java.net网站上下载webwork-2.1.zip;
(2)将压缩包解压,使用WebWork安装所需要的lib包括webwork-2.1.jar和lib/core文件夹中的jar文件
2、建立Web应用程序
(1)这里假设你安装了Servlet容器,并知道如何创建一个Web应用程序;如果你不知道,建议学习Apache Tomcat(Apache Jakarta项目中的一个免费Servlet容器);
(2)复制需要的运行库(webwork-2.1.jar和lib/core/*.jar)到Web应用程序的WEB-INF/lib文件夹中;
(3)WebWork配置web.xml、xwork.xml和validators.xml文件;
(4)web.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 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.1.jar
- </taglib-location>
- </taglib></web-app>
为了使用WebWork,必须注册ServletDispatcher,并映射到*.action;作为可选,如果要使用WebWork的tags,要声明WebWork的taglib描述;
(5)在WEB-INF/classes目录下创建WebWork的配置文件xwork.xml,下面是一个配置框架(会在教程的后面增加内容):
- <!DOCTYPE xwork PUBLIC
- "-//OpenSymphony Group//XWork 1.0//EN"
- "http://www.opensymphony.com/xwork/xwork-1.0.dtd">
- <xwork>
- <!-- Include webwork defaults (from WebWork-2.1 JAR).
- -->
- <include file="webwork-default.xml" />
- <!-- Configuration for the default package. -->
- <package name="default" extends="webwork-default">
- </package>
- </xwork>
这做两件事:
◆导入webwork-default.xml(位于webwork-2.1.jar中)的配置信息,包含WebWork应用程序的缺省配置;
◆定义名为default的package,用于actions、 results和interceptors的注册;这个package继承webwork-default,以继承其中定义的配置;
(6)在WEB-INF/classes目录下创建validators.xml。包括以下内容:
- <!DOCTYPE validators PUBLIC
- "-//OpenSymphony Group//XWork Validator1.0//EN"
- "http://www.opensymphony.com/xwork/
- xwork-validator-1.0.dtd">
- <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>
这个文件定义可以使用的有效Validators。
【编辑推荐】