• Webwork 学习笔记


    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     @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 }
      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

    下图为简易的时序图

  • 相关阅读:
    python --github 刷题
    http://www.rehack.cn/techshare/webbe/php/3391.html
    SQL 百万级数据提高查询速度的方法
    开学收好这 17 种工具 App,让你新学期学习更有效率
    Git文件常见下标符号说明
    TortoiseGit功能介绍
    gitlab图形化使用教程 (mtm推荐)
    gitlab 服务器的搭建与使用全过程(一)
    Git详解之一 Git实战
    Git使用基础篇
  • 原文地址:https://www.cnblogs.com/aeolia/p/4211181.html
Copyright © 2020-2023  润新知