Webwork 學習筆記

來源:互聯網
上載者:User

標籤:

1. 首先配置一個簡單的webwork應用

核心jar:

commons-logging.jar
ognl.jar
oscore.jar
velocity-dep.jar
webwork-2.1.7.jar
xwork.jar

  1. 配置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>
    View Code
  2. 建立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     @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 }
    View Code
  3. 配置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 Code
  4. 建立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>
    View Code

     

完成,現在可以訪問http://localhost:8080/web/HelloWorld.action

為簡易的時序圖

Webwork 學習筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.