Java Reference
In-Depth Information
Clean URLs Without a Prefix
Normally, we need to map a prefix (or a suffix) in web.xml to deter-
mine which URLs will be handled by Stripes. It's not a Stripes-specific
thing; it's a basic Servlet specification requirement. Mapping all URLs
to Stripes with /* is usually a bad idea, because some URLs target non-
Stripes resources, such as images, CSS files, JavaScript files, static
. html files, and so on.
In the previous example, we used the /action prefix to differentiate
requests that should go to Stripes from all other requests. So, we had
URL bindings such as this:
/action/contact_list/...
/action/message_list/...
/action/register/...
That's pretty clean, but that Unstoppable Force of Nature might return
and demand the removal of that /action prefix so that URLs are even
simpler:
/contact_list/...
/message_list/...
/register/...
So, now what? Without a common prefix, how do we map URLs to
Stripes in web.xml ? We could map each prefix, such as /contact_list/* ,
/message_list/* , and so on. But that's way too painful, and it could come
back and bite us later if we happen to have an image file under /con-
tact_list/icon.gif , for example.
Have no fear. We can get prefixless clean URLs, without tedious config-
uration and without having to worry about static files conflicting with
Stripes bindings. Ben Gunter, the Stripes committer who implemented
clean URL support, had one more trick up his sleeve to address this
requirement.
Ben came up with the clever DynamicMappingFilter to which we can map
all URLs with /* . The filter takes into account that some requests target
non-Stripes resources. Using DynamicMappingFilter , instead of this:
/action/contact_list/view/5
we can use this:
/contact_list/view/5
 
 
Search WWH ::




Custom Search