来公司之前我对WebWork,Stuts,AJAX一无所知,每日耳濡目染,总算对这些曾经无比神秘的东西有了些许模糊的认识.前些日子Mr.zhang说我的下一个项目要WebWork或者Hibernate任选其一,考虑到FrameWork之类的东西比较火热牛X一些,我决定开始我的WebWork探索之路.花了个把小时,参考了几篇文章,总算run出了一个HelloWorld程序.现把步骤记录下来,以备日后查看.
(1) 在tomcat/webapp/中建立一个context(上下文)(tomcat/webapp/webwork);
将webwork中的webwork_2.2.1.jar和/lib/default中的所有.jar文件
加入到tomcat/webapp/webwork/WEB-INF/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.2.1.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文件
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:
<title>WebWork Tutorial</title>
<p>What's your name?</p>
<form action="hello.action" method="post">
<p><input type="text" name="person" /><input type="submit" /></p>
</form>
success.jsp:
<%@ taglib uri="webwork" prefix="ww" %>
<title>WebWork Tutorial </title>
Hello, <ww
roperty value="person" />
(6)运行!
tomcat---webapp
---webwork
---classes
---org.HelloAction
---xwork.xml
---lib(存放webwork工作的包)
---web.xml
---index.jsp
---success.jsp
有一个地方需要留意一些,就是xml文件中,各属性后面的value一定要用""括起来,这个明显不同于html自由的编码风格,这是整个配置过程中遇到的唯一问题,至于其他,只要细心一些应该可以轻松搞定.
(1) 在tomcat/webapp/中建立一个context(上下文)(tomcat/webapp/webwork);
将webwork中的webwork_2.2.1.jar和/lib/default中的所有.jar文件
加入到tomcat/webapp/webwork/WEB-INF/lib中;
(2) 修改web.xml如下:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="
![::URL::](http://www.blogcn.com/images/aurl.gif)
xmlns:xsi="
![::URL::](http://www.blogcn.com/images/aurl.gif)
xsi:schemaLocation="
![::URL::](http://www.blogcn.com/images/aurl.gif)
![::URL::](http://www.blogcn.com/images/aurl.gif)
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.2.1.jar</taglib-location>
</taglib>
</web-app>
(3)在webwork/classes中加入xwork.xml配置文件:
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN"
"
![::URL::](http://www.blogcn.com/images/aurl.gif)
<!-- 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文件
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:
<title>WebWork Tutorial</title>
<p>What's your name?</p>
<form action="hello.action" method="post">
<p><input type="text" name="person" /><input type="submit" /></p>
</form>
success.jsp:
<%@ taglib uri="webwork" prefix="ww" %>
<title>WebWork Tutorial </title>
Hello, <ww
![](http://www.blogcn.com/images/tongue.gif)
(6)运行!
tomcat---webapp
---webwork
---classes
---org.HelloAction
---xwork.xml
---lib(存放webwork工作的包)
---web.xml
---index.jsp
---success.jsp
有一个地方需要留意一些,就是xml文件中,各属性后面的value一定要用""括起来,这个明显不同于html自由的编码风格,这是整个配置过程中遇到的唯一问题,至于其他,只要细心一些应该可以轻松搞定.