Webwork 学习笔记
1. 首先配置一个简单的webwork应用
核心jar:
commons-logging.jar
ognl.jar
oscore.jar
velocity-dep.jar
webwork-2.1.7.jar
xwork.jar
- 配置web.xml
<?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> <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> <taglib> <taglib-uri>webwork</taglib-uri> <taglib-location>/WEB-INF/lib/webwork-2.1.7.jar</taglib-location> </taglib> </web-app>
- 新建action: HelloWorld.java
1 package com.aeolia.action; 2 3 import java.text.SimpleDateFormat; 4 import java.util.Date; 5 6 import com.opensymphony.util.Data; 7 import com.opensymphony.xwork.Action; 8 9 public class HelloWorld implements Action { 10 private String message; 11 private String name; 12 13 public String getName() { 14 return name; 15 } 16 17 public void setName(String name) { 18 this.name = name; 19 } 20 21 @Override 22 public String execute() throws Exception { 23 String result = ""; 24 if (this.name == null || this.name.equalsIgnoreCase("world") || this.name.equals("")) { 25 result = INPUT; 26 message = "Blank name or names of world are not allowed "; 27 } else { 28 message = "Hello World ! "; 29 java.text.SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); 30 Date date = new Date(); 31 String dateString = format.format(date); 32 message += this.name; 33 message += " time is " + dateString; 34 result = SUCCESS; 35 } 36 return result; 37 } 38 39 public String getMessage() { 40 return message; 41 } 42 43 }
- 配置xwork.xml(位于classes下)
<!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="completeStack" /> <action name="HelloWorld" class="com.aeolia.action.HelloWorld"> <result name="success">hello.jsp</result> <result name="input">name.jsp</result> </action> </package> </xwork>
- 新建view:hello.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="MS932"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <%@taglib prefix="ww" uri="webwork"%> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> Show message <ww:property value="message" /> </body> </html>
完成,现在可以访问http://localhost:8080/web/HelloWorld.action
下图为简易的时序图
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。