webwork入门文章
2008-01-05 18:44:38 来源:WEB开发网
(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 {
更多精彩
赞助商链接