public class DynamicMappingFilter
extends java.lang.Object
implements javax.servlet.Filter
A servlet filter that dynamically maps URLs to ActionBean
s. This filter can be used to
allow Stripes to dispatch requests to ActionBean
s based on their URL binding, even if
the URL to which they are bound is not explicitly mapped in web.xml
.
There are a few caveats that must be observed when using this filter:
StripesFilter
MUST be defined in web.xml
so that it will be
loaded and initialized./*
to work correctly.ActionBean
to a URL, the filter chain is interrupted.
StripesFilter
and DispatcherServlet
need not be mapped to any URL patterns in
web.xml
since this filter will determine at runtime whether or not they need to be
invoked. In fact, you don't even need to define DispatcherServlet
in web.xml
at
all because this filter uses an instance it creates and manages internally. However, some
resources, such as JSPs, may require access to the Stripes Configuration
. Thus,
StripesFilter
should be mapped to *.jsp
if you intend to access JSPs directly.
This filter takes the following approach to determining when to dispatch an ActionBean
:
404
was returned then send the error through. Otherwise ...ActionResolver
to see if an ActionBean
is mapped to the URL. If
not, then send the 404
error through. Otherwise...StripesFilter
and DispatcherServlet
One benefit of this approach is that static resources can be delivered from the same namespace to
which an ActionBean
is mapped using clean URLs. (Form more information on clean URLs, see
UrlBinding
.) For example, if your UserActionBean
is mapped to
@UrlBinding("/user/{id}/{$event}")
and you have a static file at /user/icon.gif
,
then your icon will be delivered correctly because the initial request will not have returned a
404
error.
This filter accepts one init-param. IncludeBufferSize
(optional, default 1024) sets the
number of characters to be buffered by DynamicMappingFilter.TempBufferWriter
for include requests. See
DynamicMappingFilter.TempBufferWriter
for more information.
This is the suggested mapping for this filter in web.xml
.
<filter> <description>Dynamically maps URLs to ActionBeans.</description> <display-name>Stripes Dynamic Mapping Filter</display-name> <filter-name>DynamicMappingFilter</filter-name> <filter-class> net.sourceforge.stripes.controller.DynamicMappingFilter </filter-class> </filter> <filter-mapping> <filter-name>DynamicMappingFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping>
UrlBinding
Modifier and Type | Class and Description |
---|---|
static class |
DynamicMappingFilter.ErrorTrappingResponseWrapper
An
HttpServletResponseWrapper that traps HTTP errors by overriding
sendError(int, ..) . |
static class |
DynamicMappingFilter.TempBufferWriter
A
Writer that passes characters to a PrintWriter . |
Constructor and Description |
---|
DynamicMappingFilter() |
Modifier and Type | Method and Description |
---|---|
void |
destroy() |
void |
doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain chain) |
protected void |
doOneTimeConfiguration()
Perform initialization that can't be done in
init(..) . |
protected java.lang.String |
getRequestURI(javax.servlet.http.HttpServletRequest request)
Deprecated.
Use
HttpUtil.getRequestedPath(HttpServletRequest) instead. |
void |
init(javax.servlet.FilterConfig config) |
public void init(javax.servlet.FilterConfig config) throws javax.servlet.ServletException
init
in interface javax.servlet.Filter
javax.servlet.ServletException
public void destroy()
destroy
in interface javax.servlet.Filter
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws java.io.IOException, javax.servlet.ServletException
doFilter
in interface javax.servlet.Filter
java.io.IOException
javax.servlet.ServletException
protected void doOneTimeConfiguration() throws javax.servlet.ServletException
init(..)
. This is normally called only
once, on the first invocation of doFilter(..)
.javax.servlet.ServletException
@Deprecated protected java.lang.String getRequestURI(javax.servlet.http.HttpServletRequest request)
HttpUtil.getRequestedPath(HttpServletRequest)
instead.? Copyright 2005-2006, Stripes Development Team.