public class UriMappingServletDispatcher
extends ServletDispatcher

This is a custom servlet dispatcher whose functionality is loosely based off of com.opensymphony.webwork.dispatcher.CoolUriServletDispatcher. The purpose of this dispatcher is to allow for urls where the http parameters are not passed in as ?key=value&key=value pairs but as /key/value/key/value pairs. Some call these pretty or cool urls. This servlet differs from the webwork included CoolUriServletDispatcher in that it:
  1. doesn't throw a String.subtring index out of bounds exception on my deployment ;)
  2. can handle conventional actionName.action (or any other extension) url formats
  3. assumes a format of actionName/value to set the id property on the action and NOT to set the id property on the actionName property of the action
  4. can simultaneously handle both pretty url parameters (/key1/value1...) and conventional parameters (/key1/value1?key2=value2)
Usage:
  1. Determine the url path you want to use for urls that will utilize the pretty format. I find that using: context/link/actionName works well. In this case "/link" is extra url path that will signify a pretty url. If you will always be using a pretty url format and never the standard context/actionName.action format, this step is unecessary. This is only useful when both formats should be supported and helps in the trickiness that is the servlet and web.xml request mapping.
  2. Set this servlet to be your webwork dispatcher servlet in web.xml and add an init-param signifying the url portion that you've added to your pretty urls (if any - again, if you are only using pretty formats, this is unecessary):

      <servlet>
        <servlet-name>webwork</servlet-name>
        <servlet-class>your.package.UriMappingServletDispatcher</servlet-class>
        <load-on-startup>1</load-on-startup>
        <init-param>
           <param-name>ignoreURIPortion</param-name>
           <param-value><b>/link</b></param-value>
        </init-param>
      </servlet>
     
  3. Set up your request mappings. If you are using both conventional and pretty url formats then your mappings in web.xml will look something like this:

      <servlet-mapping>
        <servlet-name>webwork</servlet-name>
        <url-pattern>*.action</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
        <servlet-name>webwork</servlet-name>
        <url-pattern><b>/link/*</b></url-pattern>
      </servlet-mapping>
     

    If you are only using pretty url formats then your mappings in web.xml will look something like more like this (or whatever will map all requests to the servlet)

      <servlet-mapping>
        <servlet-name>webwork</servlet-name>
        <url-pattern>/*</url-pattern>
      </servlet-mapping>
     

Once your web.xml is set up, you should be good to go. Now for the functionality you can expect to see:

Field Summary

static String
URI_IGNORE_CONFIG_KEY

Method Summary

protected String
getAdjustedString(String adjustable)
Get the portion of the request URI that should be analyzed for action names, parameters etc...
protected String
getUriMappedActionName(HttpServletRequest request)
The action could not be determined when the vanilla action.xxx format was used - revert to other more manual means to determine the action name.
void
init(ServletConfig servletConfig)
void
service(HttpServletRequest request, HttpServletResponse response)
protected void
serviceUriMappedRequest(HttpServletRequest request, HttpServletResponse response, String actionName)
This request has been identified as not being a vanilla request, so handle it as though it's a URI mapped request.
protected void
serviceVanillaRequest(HttpServletRequest request, HttpServletResponse response, String actionName)
This request has been identified as being a vanilla request: actionName.action?key=value&key=value...., handle it appropriately

Field Details

URI_IGNORE_CONFIG_KEY

public static final String URI_IGNORE_CONFIG_KEY

Method Details

getAdjustedString

protected String getAdjustedString(String adjustable)
Get the portion of the request URI that should be analyzed for action names, parameters etc... This is basically the URI minus the text specified in the "ignoreURIPortion" servlet init param. (only takes out the first occurance of the string - override for other functionality)
Parameters:
Returns:

getUriMappedActionName

protected String getUriMappedActionName(HttpServletRequest request)
The action could not be determined when the vanilla action.xxx format was used - revert to other more manual means to determine the action name.
Parameters:
request -
Returns:

init

public void init(ServletConfig servletConfig)
            throws ServletException

service

public void service(HttpServletRequest request,
                    HttpServletResponse response)
            throws ServletException

serviceUriMappedRequest

protected void serviceUriMappedRequest(HttpServletRequest request,
                                       HttpServletResponse response,
                                       String actionName)
This request has been identified as not being a vanilla request, so handle it as though it's a URI mapped request.
Parameters:
request -
response -
actionName -

serviceVanillaRequest

protected void serviceVanillaRequest(HttpServletRequest request,
                                     HttpServletResponse response,
                                     String actionName)
This request has been identified as being a vanilla request: actionName.action?key=value&key=value...., handle it appropriately
Parameters:
request -
response -
actionName -