打算从头开始webwork学习,第一步先搭建起webwork吧!
参考文献:webwork in action
目录结构:
[img]F:\images\1.jpg[/img]
配置:
web.xml
[code]
<?xml version="1.0" encoding="ISO-8859-1"?>
<!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>webwork</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- webwork -->
<servlet>
<servlet-name>webwork</servlet-name>
<servlet-class>
com.opensymphony.webwork.dispatcher.ServletDispatcher
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>webwork</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<!-- Tags -->
<taglib>
<taglib-uri>webwork</taglib-uri>
<taglib-location>
/WEB-INF/lib/webwork-2.1.7.jar
</taglib-location>
</taglib>
</web-app>
[/code]
xwork.xml
[code]
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN"
"http://www.opensymphony.com/xwork/xwork-1.0.dtd">
<xwork>
<include file="webwork-default.xml"/>
<package name="default" extends="webwork-default">
<default-interceptor-ref name="defaultStack"/>
<action name="helloWorld" class="webwork.action.HelloWorld">
<result name="success">/default/hello.jsp</result>
</action>
</package>
</xwork>
[/code]
webwork.properties
[code]
webwork.tag.altSyntax = true
[/code]
action:
[code]
/*
* Created on 2006-10-12
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package webwork.action;
import com.opensymphony.xwork.Action;
/**
* @author Liu
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class HelloWorld implements Action {
private String message;
public String execute() {
message = "Hello, World!";
return SUCCESS;
}
public String getMessage() {
return message;
}
}
[/code]
jsp:
index.jsp
[code]
<html>
<head><title>webwork</title></head>
<body>
hello,webwork!
<body>
</html>
[/code]
hello.jsp
[code]
<%@ taglib prefix="ww" uri="webwork" %>
<html>
<head>
<title>Hello Page</title>
</head>
<body>
The message generated by my first action is:
<ww:property value="message"/>
</body>
</html>
[/code]
运行结果:
[img]F:/images/2.jpg[/img]
[img]F:/images/3.jpg[/img]
运行成功!
参考文献:webwork in action
目录结构:
[img]F:\images\1.jpg[/img]
配置:
web.xml
[code]
<?xml version="1.0" encoding="ISO-8859-1"?>
<!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>webwork</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- webwork -->
<servlet>
<servlet-name>webwork</servlet-name>
<servlet-class>
com.opensymphony.webwork.dispatcher.ServletDispatcher
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>webwork</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<!-- Tags -->
<taglib>
<taglib-uri>webwork</taglib-uri>
<taglib-location>
/WEB-INF/lib/webwork-2.1.7.jar
</taglib-location>
</taglib>
</web-app>
[/code]
xwork.xml
[code]
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN"
"http://www.opensymphony.com/xwork/xwork-1.0.dtd">
<xwork>
<include file="webwork-default.xml"/>
<package name="default" extends="webwork-default">
<default-interceptor-ref name="defaultStack"/>
<action name="helloWorld" class="webwork.action.HelloWorld">
<result name="success">/default/hello.jsp</result>
</action>
</package>
</xwork>
[/code]
webwork.properties
[code]
webwork.tag.altSyntax = true
[/code]
action:
[code]
/*
* Created on 2006-10-12
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package webwork.action;
import com.opensymphony.xwork.Action;
/**
* @author Liu
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class HelloWorld implements Action {
private String message;
public String execute() {
message = "Hello, World!";
return SUCCESS;
}
public String getMessage() {
return message;
}
}
[/code]
jsp:
index.jsp
[code]
<html>
<head><title>webwork</title></head>
<body>
hello,webwork!
<body>
</html>
[/code]
hello.jsp
[code]
<%@ taglib prefix="ww" uri="webwork" %>
<html>
<head>
<title>Hello Page</title>
</head>
<body>
The message generated by my first action is:
<ww:property value="message"/>
</body>
</html>
[/code]
运行结果:
[img]F:/images/2.jpg[/img]
[img]F:/images/3.jpg[/img]
运行成功!