Writing WebWork HelloWorld App
From Foochal
Contents |
[edit]
Getting the software
- Download the webwork release from the OpenSymphony website.
- Unzip the zip file in a folder, for example ‘webwork’.
[edit]
Create a project
- Create a new Eclipse dynamic web project. We’ll chose the name ‘wwdemo’ for the rest of this article.
- Copy the webwork/src/java/template directory to your wwdemo/WebContent directory
[edit]
Setting up the project
[edit]
web.xml
Copy the following to your web.xml
<?xml version="1.0"?> <!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> <display-name>My WebWork Application</display-name> <filter> <filter-name>webwork</filter-name> <filter-class>com.opensymphony.webwork.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>webwork</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <taglib> <taglib-uri>/webwork</taglib-uri> <taglib-location>/WEB-INF/lib/webwork.jar</taglib-location> </taglib> </web-app>
[edit]
xwork.xml
Create the following xwork.xml in your WebContent/WEB-INF/classes directory:
<!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="example.helloworld.HelloWorld"> <result name="success">hello.jsp</result> </action> </package> </xwork>
[edit]
Required Libraries
Copy the following jars:
- xwork.jar
- webwork.jar
[edit]
HelloWorld.java
Create an action file HelloWorld.java
package demo;
import com.opensymphony.xwork.Action;
import java.text.DateFormat;
import java.util.*;
public class HelloWorld implements Action {
private String message;
public String execute() {
message = "Hello, WebWorld!\n";
message += "The time is:\n";
message += DateFormat.getDateInstance().format(new Date());
return SUCCESS;
}
public String getMessage() {
return message;
}
}
[edit]
hello.jsp
Create a view hello.jsp
<%@ taglib prefix="ww" uri="/webwork" %> <html> <head> <title>Hello Page</title> </head> <body> The message generated by my first action is: <ww:property value="message"/> </body> </html>
[edit]
Spring config
Create the file applicationContext.xml and place it in WEB-INF. This is for initializing spring beans:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans default-autowire="autodetect"></beans>
[edit]
WebWork config
Create a file called webwork.properties and place it in classes directory:
webwork.objectFactory = spring webwork.devMode = true
[edit]
Run the program
Goto: http://localhost:8080/wwdemo/helloWorld.action
[edit]
External links
The relevant documentation is at http://www.opensymphony.com/webwork/wikidocs/Tutorial.html

