WebWork Study Notes

Source: Internet
Author: User

1. First configure a simple webwork application

Core jar:

Commons-logging.jar
Ognl.jar
Oscore.jar
Velocity-dep.jar
Webwork-2.1.7.jar
Xwork.jar

  1. Configure 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. New Action:HelloWorld.java
    1  Packagecom.aeolia.action;2 3 ImportJava.text.SimpleDateFormat;4 Importjava.util.Date;5 6 ImportCom.opensymphony.util.Data;7 Importcom.opensymphony.xwork.Action;8 9  Public classHelloWorldImplementsAction {Ten     PrivateString message; One     PrivateString name; A  -      PublicString GetName () { -         returnname; the     } -  -      Public voidsetName (String name) { -          This. Name =name; +     } -  + @Override A      PublicString Execute ()throwsException { atString result = ""; -         if( This. Name = =NULL|| This. Name.equalsignorecase ("World") | | This. Name.equals ("")) { -result =INPUT; -message = "Blank name or names of world is not allowed"; -}Else { -message = "Hello world!"; inJava.text.SimpleDateFormat format =NewSimpleDateFormat ("Yyyy-mm-dd"); -Date Date =NewDate (); toString datestring =Format.format (date); +Message + = This. Name; -Message + = "Time is" +datestring; theresult =SUCCESS; *         } $         returnresult;Panax Notoginseng     } -  the      PublicString getMessage () { +         returnmessage; A     } the  +}
    View Code
  3. Configuration Xwork.xml (located under Classes)
    <!DOCTYPE xwork Public "-//opensymphony group//xwork 1.0//en" "Http://www.opensymphony.com/xwork/xwork-1.0.dtd" ><xwork>    <includefile= "Webwork-default.xml" />    < Packagename= "Default"extends= "Webwork-default">        <Default-interceptor-refname= "Completestack" />        <Actionname= "HelloWorld"class= "Com.aeolia.action.HelloWorld">            <resultname= "Success">hello.jsp</result>            <resultname= "Input">name.jsp</result>        </Action>    </ Package></xwork>
    View Code
  4. New 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"%><Metahttp-equiv= "Content-type"content= "text/html; charset=iso-8859-1"><title>Insert Title here</title></Head><Body>Show Message<Ww:propertyvalue= "message" /></Body></HTML>
    View Code

Complete, you can now access http://localhost:8080/web/HelloWorld.action

For a simple timing diagram

WebWork Study Notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.