WebWork 2 : TutorialLesson02
This page last changed on Sep 16, 2004 by vitorsouza.
Lesson 2: Setting up the Web ApplicationIt is assumed that you have a Servlet container set up and you know how to create a web application. If you don't, we suggest you learn about Apache Tomcat, which is a free Servlet container from the Apache Jakarta Project, or Resin, from Caucho Technology, which is free for non-comercial use.To use WebWork, copy the required libraries, described in the previous lesson (webwork-2.1.1.jar and lib/core/*.jar), to the directory WEB-INF/lib of the Web Application. Then, configure web.xml and create other two XML files: xwork.xml and validators.xml. These three files will be explained below. web.xml:Change your web application's web.xml file to look somewhat like this: <?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> <servlet> <servlet-name>webwork</servlet-name> <servlet-class>com.opensymphony.webwork.dispatcher.ServletDispatcher</servlet-class> <load-on-startup>1</load-on-startup> </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.1.jar</taglib-location> </taglib> </web-app> To use WebWork you must register ServletDispatcher and its mapping to *.action. It will be explained why those lines are important in the section about Actions in the next lesson. In the example above WebWork's taglib descriptor is also declared to allow the usage of WebWork tags (more about WebWork tags on lesson 4.1) – it is safe to remove it if WebWork tags are not being used. Read more: web.xml xwork.xml:At the root of the classpath (namely, WEB-INF/classes) create a file called xwork.xml, which WebWork uses to configure itself. For now, place the following content in it:<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN" "http://www.opensymphony.com/xwork/xwork-1.0.dtd"> <xwork> <!-- Include webwork defaults (from WebWork JAR). --> <include file="webwork-default.xml" /> <!-- Configuration for the default package. --> <package name="default" extends="webwork-default"> </package> </xwork> This is just a skeleton of a configuration file, which will be incremented as we go through the lessons. As of now, it is only doing two things:
Read more: xwork.xml validators.xml:Again, at the root of the classpath, create a file called validators.xml, with the following content:<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.dtd"> <validators> <validator name="required" class="com.opensymphony.xwork.validator.validators.RequiredFieldValidator"/> <validator name="requiredstring" class="com.opensymphony.xwork.validator.validators.RequiredStringValidator"/> <validator name="int" class="com.opensymphony.xwork.validator.validators.IntRangeFieldValidator"/> <validator name="date" class="com.opensymphony.xwork.validator.validators.DateRangeFieldValidator"/> <validator name="expression" class="com.opensymphony.xwork.validator.validators.ExpressionValidator"/> <validator name="fieldexpression" class="com.opensymphony.xwork.validator.validators.FieldExpressionValidator"/> <validator name="email" class="com.opensymphony.xwork.validator.validators.EmailValidator"/> <validator name="url" class="com.opensymphony.xwork.validator.validators.URLValidator"/> <validator name="visitor" class="com.opensymphony.xwork.validator.validators.VisitorFieldValidator"/> <validator name="conversion" class="com.opensymphony.xwork.validator.validators.ConversionErrorFieldValidator"/> </validators> This file defines the validators that are available for use. Read more: Validation All Set Up!Now there is a skeleton of the WebWork application already set up. Next lessons will teach how to use WebWork's actions, views and interceptors.Previous Lesson | Next Lesson |
![]() |
Document generated by Confluence on Dec 14, 2004 16:36 |