|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.stripes.controller.DynamicMappingFilter
public class DynamicMappingFilter
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
Nested Class Summary | |
---|---|
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 Summary | |
---|---|
DynamicMappingFilter()
|
Method Summary | |
---|---|
void |
destroy()
|
void |
doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain)
|
protected void |
doOneTimeConfiguration()
Perform initialization that can't be done in init(..) . |
protected String |
getRequestURI(HttpServletRequest request)
Deprecated. Use HttpUtil.getRequestedPath(HttpServletRequest) instead. |
void |
init(FilterConfig config)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DynamicMappingFilter()
Method Detail |
---|
public void init(FilterConfig config) throws ServletException
init
in interface Filter
ServletException
public void destroy()
destroy
in interface Filter
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
doFilter
in interface Filter
IOException
ServletException
protected void doOneTimeConfiguration() throws ServletException
init(..)
. This is normally called only
once, on the first invocation of doFilter(..)
.
ServletException
@Deprecated protected String getRequestURI(HttpServletRequest request)
HttpUtil.getRequestedPath(HttpServletRequest)
instead.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |