(1) 在tomcat/webapp/中建立一个context(上下文)(tomcat/webapp/webwork);
将webwork中的webwork_2.1.5.jar和/lib/core中的所有.jar文件
加入到tomcat/webapp/webwork/web-info/lib中;
(2) 修改web.xml如下:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<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.5.jar</taglib-location>
</taglib>
</web-app>
(3)在webwork/classes中加入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">
<!-- Default interceptor stack. -->
<default-interceptor-ref name="defaultStack" />
<action name="hello" class="org.HelloAction">
<result name="error" type="dispatcher">index.jsp</result>
<result name="success" type="dispatcher">success.jsp</result>
</action>
</package>
</xwork>
(4)创建HelloAction.java文件(HelloAction 类是用来处理请求的):
package org;
import com.opensymphony.xwork.ActionSupport;
public class HelloAction extends ActionSupport {
String person;
public String getPerson() {
return person;
}
public void setPerson(String person) {
this.person = person;
}
public String execute() throws Exception {
if ((person == null) || (person.length() == 0)) return ERROR;
else return SUCCESS;
}
}
(5)创建两个jsp组件:index.jsp和success.jsp
index.jsp:
<html>
<head>
<title>WebWork Tutorial</title>
</head>
<body>
<p>What's your name?</p>
<form action="hello.action" method="post">
<p><input type="text" name="person" /><input type="submit" /></p>
</form>
</body>
</html>
success.jsp:
<%@ taglib uri="webwork" prefix="ww" %>
<html>
<head>
<title>WebWork Tutorial </title>
</head>
<body>
Hello, <ww:property value="person" />
</body>
</html>
(6)运行!
tomcat---webapp
---webwork
---classes
---org.HelloAction
---xwork.xml
---lib(存放webwork工作的包)
---web.xml
---index.jsp
---success.jsp