WebWork 2 : web.xml
This page last changed on May 23, 2004 by ctran.
Configuring the web.xml file is for the most part a pretty straight forward exercise. Configuring the ServletDispatcherThe most common entry point for calling actions in your application will be calling an URL directly or having the user submit a form to an action. The following is an example of how to configure the ServletDispatcher to process actions.<!-- This entry is required to have the framework process calls to WebWork actions --> <servlet> <servlet-name>webworkDispatcher</servlet-name> <servlet-class>com.opensymphony.webwork.dispatcher.ServletDispatcher</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>webworkDispatcher</servlet-name> <url-pattern>*.action</url-pattern> </servlet-mapping> NOTE: The above configuration assumes that actions will use the ".action" extension. If you want your actions to use a different extension, change the url-pattern element to the desired extension and update your calling code to specify that extension. Configuring CoolUriServletDispatcher (optional)A custom servlet dispatcher that maps servlet paths to actions. This can be used instead of the above ServletDispatcher. The format is the following: http://HOST/ACTION_NAME/PARAM_NAME1/PARAM_VALUE1/PARAM_NAME2/PARAM_VALUE2 You can have as many parameters you'd like to use. Alternatively the URL can be shortened to the following: http://HOST/ACTION_NAME/PARAM_VALUE1/PARAM_NAME2/PARAM_VALUE2 This is the same as: http://HOST/ACTION_NAME/ACTION_NAME/PARAM_VALUE1/PARAM_NAME2/PARAM_VALUE2 Suppose for example we would like to display some articles by id at using the following URL sheme: http://HOST/article/ID All we would have to do is to map the /article/* to this servlet and declare in WebWork an action named article. This action would set its article parameter ID: <servlet> <servlet-name>coolDispatcher</servlet-name> <servlet-class>com.opensymphony.webwork.dispatcher.CoolUriServletDispatcher</servlet-class> </servlet> <servlet-mapping> <servlet-name>coolDispatcher</servlet-name> <url-pattern>/article/*</url-pattern> </servlet-mapping> Configuring Velocity Support (optional)WebWork uses Velocity as the underlying template system for the custom JSP tag libraries. However, it does not require the WebWorkVelocityServlet to be configured. You only need to do that if you want to invoke velocity templates directly or from "dispatcher" result type. If so, you need to add the following: <servlet> <servlet-name>velocity</servlet-name> <servlet-class>com.opensymphony.webwork.views.velocity.WebWorkVelocityServlet</servlet-class> <load-on-startup>10</load-on-startup> </servlet> <servlet-mapping> <servlet-name>velocity</servlet-name> <url-pattern>*.vm</url-pattern> </servlet-mapping> Configuring tag libraries (optional)The tag libraries are an optional part of the framework that provides a number of benefits when working with forms and actions. See the JSP Tags reference for more information. To use them, you need to specify the location of the tld (Tag Library Descriptor):<taglib> <taglib-uri>webwork</taglib-uri> <taglib-location>/WEB-INF/lib/webwork-2.1.jar</taglib-location> </taglib> If your application server doesn't support taglib inside a jar, you will need to extract the webwork.tld, copy it to /WEB-INF and change the above to: <taglib> <taglib-uri>webwork</taglib-uri> <taglib-location>/WEB-INF/webwork.tld</taglib-location> </taglib> NOTE: webwork.tld can be placed anywhere inside your webapp directory. Configuring Freemarker support (optional)Add the following: <servlet> <servlet-name>freemarker</servlet-name> <servlet-class>com.opensymphony.webwork.views.freemarker.FreemarkerServlet</servlet-class> <load-on-startup>10</load-on-startup> </servlet> <servlet-mapping> <servlet-name>freemarker</servlet-name> <url-pattern>*.ftl</url-pattern> </servlet-mapping> Configuring IoC / LifeCycle (optional)See IoC Configuration |
![]() |
Document generated by Confluence on Dec 14, 2004 16:37 |