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