今天開始學習WebWork,呵……結合《WebWork教程-0.90版》和Webwork官方的教程來學習。
WebWork2.2和WebWork2.1在配置上有一些區別,現在把WebWork2.2的一些配置放進來。
web.xml
<?xml?version="1.0"?encoding="UTF-8"?>
<web-app?version="2.4"?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">

????<filter>
????????<filter-name>webwork</filter-name>
????????<filter-class>com.opensymphony.webwork.dispatcher.FilterDispatcher</filter-class>
????</filter>

????<filter-mapping>
????????<filter-name>webwork</filter-name>
????????<url-pattern>/*</url-pattern>
????</filter-mapping>

????<listener>
????????<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
????</listener>
</web-app>

xwork.xml
<?xml?version="1.0"?encoding="UTF-8"?>
<!DOCTYPE?xwork?PUBLIC?"-//OpenSymphony?Group//XWork?1.1.1//EN"
"http://www.opensymphony.com/xwork/xwork-1.1.1.dtd">

<xwork>
????<!--?Include?webwork?defaults?(from?WebWork?JAR).?-->
????<include?file="webwork-default.xml"?/>

????<!--?Configuration?for?the?default?package.?-->
???<package?name="default"?extends="webwork-default">
?????<!--?Include?webwork?defaults?(from?WebWork?JAR).?-->
?????<default-interceptor-ref?name="completeStack"/>

??????<action?name="helloWorld"
?????????class="org.javadream.webwork.ch01.HelloWorld">
?????????<result?name="success">hello.jsp</result>
??????</action>
???</package>

</xwork>
webwork.properties
webwork.locale=zh_CN
webwork.i18n.encoding=GB2312

webwork.objectFactory=spring
這里中文有問題,必須要在webwork.properties中進入設置.webwork.objectFactory=spring是用spring作為默認的IoC容器。
編寫一個Action:
package?org.javadream.webwork.ch01;

import?com.opensymphony.xwork.Action;

import?java.text.DateFormat;
import?java.util.*;


public?class?HelloWorld?implements?Action?
{
private?String?message;


?public?String?execute()?
{
???message?=?"Hello,?WebWorld!,你好,Web世界\n";
???message?+=?"The?time?is:\n";
???message?+=?DateFormat.getDateInstance().format(new?Date());;
???
???//message?=?message.replaceAll("\n",?"<br>");

???return?SUCCESS;
?}


?public?String?getMessage()?
{
???return?message;
?}

}
編寫一個視圖jsp文件:

<%@?page?language="java"?contentType="text/html;?charset=gb2312"?pageEncoding="gb2312"%>

<%@?taglib?prefix="ww"?uri="/webwork"%>
<html>
????<head>
????????<title>Hello?Page</title>
????</head>
????<body>
????????The?message?generated?by?my?first?action?is:
????????<br>
????????<font?color="red"><ww:property?value="message"?/></font>
????</body>
</html>
這里要注意,<%@ taglib prefix="ww" uri="/webwork"%>必須要用uri="/webwork",因為要讓他在webwork.jar中查找webwork.tld,因為我們在web.xml并沒有定義這個"webwork"這個uri。
WebWork2.2和WebWork2.1在配置上有一些區別,現在把WebWork2.2的一些配置放進來。
web.xml



















xwork.xml




















webwork.properties




這里中文有問題,必須要在webwork.properties中進入設置.webwork.objectFactory=spring是用spring作為默認的IoC容器。
編寫一個Action:































編寫一個視圖jsp文件:














這里要注意,<%@ taglib prefix="ww" uri="/webwork"%>必須要用uri="/webwork",因為要讓他在webwork.jar中查找webwork.tld,因為我們在web.xml并沒有定義這個"webwork"這個uri。