Source

webwork / docs / webconfig.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <title>WebWork Documentation</title>
  <link type="text/css" href="main.css" rel="STYLESHEET"/>
</head>
<body>
  <div id="page-logo">
    <a href="index.html"><img src="logo-small.png" border="0"/></a>
  </div>
    <div class="snip-title">
	  <h1 class="snip-name">Configuring web.xml
  
  </h1>
  </div>
<div id="snip-content" class="snip-content">

 <div class="snip-attachments"></div>
 
 <h3 class="heading-1">Configuring web.xml
</h3><p class="paragraph"/>Configuring the web.xml file is for the most part a pretty straight forward exercise. One area though that might not be immediately clear is why Velocity support should be configured. WebWork 2 has a JSP tag library that uses Velocity for the underlying template system and needs this to correctly render output. 
<h3 class="heading-1-1">Configuring the ServletDispatcher
</h3><p class="paragraph"/>The 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.<p class="paragraph"/><div class="code"><pre>&#60;!&#45;&#45; This entry is required to have the framework process calls to WebWork 2 actions &#45;&#45;&#62;
&#60;servlet&#62;
  &#60;servlet&#45;name&#62;webwork&#60;/servlet&#45;name&#62;
  &#60;servlet&#45;class&#62;com.opensymphony.webwork.dispatcher.ServletDispatcher&#60;/servlet&#45;class&#62;
&#60;/servlet&#62;<p class="paragraph"/>&#60;servlet&#45;mapping&#62;
  &#60;servlet&#45;name&#62;webwork&#60;/servlet&#45;name&#62;
  &#60;url&#45;pattern&#62;&#42;.action&#60;/url&#45;pattern&#62;
&#60;/servlet&#45;mapping&#62;</pre></div><p class="paragraph"/>NOTE: The above configuration assumes that actions will use the ".action" extension. If you want your actions to use a different extension, change the <i class="italic">url-pattern</i> element to the desired extension and update your calling code to specify that extension.
<h3 class="heading-1-1">Configuring Velocity Support
</h3><p class="paragraph"/>WebWork 2 uses Velocity as the underlying template system for the custom JSP tag libraries. It is critical that Velocity support be configured to enable the JSP tag libraries to render correctly. The following is an example of how to enable Velocity support in WebWork 2.<p class="paragraph"/><div class="code"><pre>&#60;servlet&#62;
  &#60;servlet&#45;name&#62;velocity&#60;/servlet&#45;name&#62; 
  &#60;servlet&#45;class&#62;com.opensymphony.webwork.views.velocity.WebWorkVelocityServlet&#60;/servlet&#45;class&#62; 
  &#60;load&#45;on&#45;startup&#62;1&#60;/load&#45;on&#45;startup&#62; 
&#60;/servlet&#62;<p class="paragraph"/>&#60;servlet&#45;mapping&#62;
  &#60;servlet&#45;name&#62;velocity&#60;/servlet&#45;name&#62; 
  &#60;url&#45;pattern&#62;&#42;.vm&#60;/url&#45;pattern&#62; 
&#60;/servlet&#45;mapping&#62;</pre></div><p class="paragraph"/>NOTE: The <i class="italic">load-on-startup</i> element has to be specified to insure that the Velocity servlet is loaded before be accessed.
<h3 class="heading-1-1">Configuring IoC / LifeCycle
</h3><p class="paragraph"/>The following entries are required for IoC:<p class="paragraph"/><div class="code"><pre>&#60;filter&#62;
  &#60;filter&#45;name&#62;container&#60;/filter&#45;name&#62;
  &#60;filter&#45;class&#62;com.opensymphony.webwork.lifecycle.RequestLifecycleFilter&#60;/filter&#45;class&#62;
&#60;/filter&#62;<p class="paragraph"/>&#60;filter&#45;mapping&#62;
  &#60;filter&#45;name&#62;container&#60;/filter&#45;name&#62;
  &#60;url&#45;pattern&#62;/&#42;&#60;/url&#45;pattern&#62;
&#60;/filter&#45;mapping&#62;<p class="paragraph"/>&#60;listener&#62;
  &#60;listener&#45;class&#62;com.opensymphony.webwork.lifecycle.ApplicationLifecycleListener&#60;/listener&#45;class&#62;
&#60;/listener&#62;<p class="paragraph"/>&#60;listener&#62;
  &#60;listener&#45;class&#62;com.opensymphony.webwork.lifecycle.SessionLifecycleListener&#60;/listener&#45;class&#62;
&#60;/listener&#62;</pre></div><p class="paragraph"/>The component interceptor will also need to be present within the xwork.xml configuration.
<h3 class="heading-1-1">Configuring tag libraries
</h3><p class="paragraph"/>The following is an example of how to configure the WebWork 2 tag libraries. The tag libraries are an optional part of the framework that provides a number of benefits when working with forms and actions. If you would like to store the WebWork 2 Tag Library Descriptor (webwork.tld) in another location, please update the <i class="italic">taglib-location</i> element.<p class="paragraph"/><div class="code"><pre>&#60;taglib&#62;
  &#60;taglib&#45;uri&#62;webwork&#60;/taglib&#45;uri&#62; 
  &#60;taglib&#45;location&#62;/WEB&#45;INF/webwork.tld&#60;/taglib&#45;location&#62; 
&#60;/taglib&#62;</pre></div><p class="paragraph"/>NOTE: If you are not using the WebWork 2 tag libraries the above code is not required.
  </div>
</body>
</html>