首页 > 代码库 > Webwork 学习笔记
Webwork 学习笔记
1. 首先配置一个简单的webwork应用
核心jar:
commons-logging.jar
ognl.jar
oscore.jar
velocity-dep.jar
webwork-2.1.7.jar
xwork.jar
- 配置web.xmlView 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> <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 View Code
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 @Override22 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下)View 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="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 View Code
<%@ 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
下图为简易的时序图
Webwork 学习笔记
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。