Serializable, javax.servlet.Filter, javax.servlet.FilterConfigBrowserHelperFilter, CacheFilter, FileUploadFilter, GZIPFilter, ImageFilter, ThrottleFilter, TimingFilter, TrimWhiteSpaceFilterpublic abstract class GenericFilter extends Object implements javax.servlet.Filter, javax.servlet.FilterConfig, Serializable
GenericFilter is inspired by GenericServlet, and
implements the Filter and FilterConfig interfaces.
GenericFilter makes writing filters easier. It provides simple
versions of the lifecycle methods init and destroy
and of the methods in the FilterConfig interface.
GenericFilter also implements the log methods,
declared in the ServletContext interface.
GenericFilter has an auto-init system, that automatically invokes
the method matching the signature void setX(<Type>),
for every init-parameter x. Both camelCase and lisp-style parameter
naming is supported, lisp-style names will be converted to camelCase.
Parameter values are automatically converted from string representation to
most basic types, if necessary.
doFilterImpl(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) doFilterImpl} method.Filter,
FilterConfig,
Serialized Form| Modifier and Type | Field | Description |
|---|---|---|
protected boolean |
oncePerRequest |
Indicates if this filter should run once per request (
true),
or for each forward/include resource (false). |
| Constructor | Description |
|---|---|
GenericFilter() |
Does nothing.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
destroy() |
Called by the web container to indicate to a filter that it is being
taken out of service.
|
void |
doFilter(javax.servlet.ServletRequest pRequest,
javax.servlet.ServletResponse pResponse,
javax.servlet.FilterChain pFilterChain) |
The
doFilter method of the Filter is called by the container
each time a request/response pair is passed through the chain due to a
client request for a resource at the end of the chain. |
protected abstract void |
doFilterImpl(javax.servlet.ServletRequest pRequest,
javax.servlet.ServletResponse pResponse,
javax.servlet.FilterChain pChain) |
Invoked once, or each time a request/response pair is passed through the
chain, depending on the
oncePerRequest member variable. |
javax.servlet.FilterConfig |
getFilterConfig() |
Gets the
FilterConfig for this filter. |
String |
getFilterName() |
Returns the filter-name of this filter as defined in the deployment
descriptor.
|
String |
getInitParameter(String pKey) |
Returns a
String containing the value of the named
initialization parameter, or null if the parameter does not exist. |
Enumeration |
getInitParameterNames() |
Returns the names of the servlet's initialization parameters as an
Enumeration of String objects, or an empty
Enumeration if the servlet has no initialization parameters. |
javax.servlet.ServletContext |
getServletContext() |
Returns a reference to the
ServletContext in which the caller is
executing. |
void |
init() |
A convenience method which can be overridden so that there's no need to
call
super.init(config). |
void |
init(javax.servlet.FilterConfig pConfig) |
Called by the web container to indicate to a filter that it is being
placed into service.
|
protected void |
log(String pMessage) |
Writes the specified message to a servlet log file, prepended by the
filter's name.
|
protected void |
log(String pMessage,
Throwable pThrowable) |
Writes an explanatory message and a stack trace for a given
Throwable to the servlet log file, prepended by the
filter's name. |
void |
setFilterConfig(javax.servlet.FilterConfig pFilterConfig) |
Deprecated.
For compatibility only, use
init instead. |
void |
setOncePerRequest(boolean pOncePerRequest) |
Specifies if this filter should run once per request (
true),
or for each forward/include resource (false). |
protected boolean oncePerRequest
true),
or for each forward/include resource (false).
Set this variable to true, to make sure the filter runs once per request.
NOTE: As of Servlet 2.4, this field
should always be left to it's default value (false).
filter-mapping element
of the web-descriptor should include a dispatcher element:
<dispatcher>REQUEST</dispatcher>
public void init(javax.servlet.FilterConfig pConfig)
throws javax.servlet.ServletException
FilterConfig object it
receives from the servlet container for later use.
Generally, there's no reason to override this method, override the
no-argument init instead. However, if you are
overriding this form of the method,
always call super.init(config).
This implementation will also set all configured key/value pairs, that
have a matching setter method annotated with InitParam.init in interface javax.servlet.FilterpConfig - the filter configjavax.servlet.ServletException - if an error occurs during initFilter.init(javax.servlet.FilterConfig),
init,
BeanUtil.configure(Object, java.util.Map, boolean)public void init()
throws javax.servlet.ServletException
super.init(config).javax.servlet.ServletException - if an error occurs during initinit(FilterConfig)public final void doFilter(javax.servlet.ServletRequest pRequest,
javax.servlet.ServletResponse pResponse,
javax.servlet.FilterChain pFilterChain)
throws IOException,
javax.servlet.ServletException
doFilter method of the Filter is called by the container
each time a request/response pair is passed through the chain due to a
client request for a resource at the end of the chain.
Subclasses should not override this method, but rather the
abstract doFilterImpl(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) doFilterImpl} method.doFilter in interface javax.servlet.FilterpRequest - the servlet requestpResponse - the servlet responsepFilterChain - the filter chainIOExceptionjavax.servlet.ServletExceptionFilter.doFilter,
doFilterImplprotected abstract void doFilterImpl(javax.servlet.ServletRequest pRequest,
javax.servlet.ServletResponse pResponse,
javax.servlet.FilterChain pChain)
throws IOException,
javax.servlet.ServletException
oncePerRequest member variable.pRequest - the servlet requestpResponse - the servlet responsepChain - the filter chainIOException - if an I/O error occursjavax.servlet.ServletException - if an exception occurs during the filter processoncePerRequest,
doFilter,
Filter.doFilterpublic void destroy()
destroy in interface javax.servlet.FilterFilter.destroy()public String getFilterName()
getFilterName in interface javax.servlet.FilterConfigFilterConfig.getFilterName()public javax.servlet.ServletContext getServletContext()
ServletContext in which the caller is
executing.getServletContext in interface javax.servlet.FilterConfigServletContext object, used by the caller to
interact with its servlet containerFilterConfig.getServletContext(),
ServletContextpublic String getInitParameter(String pKey)
String containing the value of the named
initialization parameter, or null if the parameter does not exist.getInitParameter in interface javax.servlet.FilterConfigpKey - a String specifying the name of the
initialization parameterString containing the value of the initialization
parameterpublic Enumeration getInitParameterNames()
Enumeration of String objects, or an empty
Enumeration if the servlet has no initialization parameters.getInitParameterNames in interface javax.servlet.FilterConfigEnumeration of String objects
containing the mNames of the servlet's initialization parametersprotected void log(String pMessage)
pMessage - the log messageServletContext.log(String)protected void log(String pMessage, Throwable pThrowable)
Throwable to the servlet log file, prepended by the
filter's name.pMessage - the log messagepThrowable - the exceptionServletContext.log(String,Throwable)public void setFilterConfig(javax.servlet.FilterConfig pFilterConfig)
init instead.pFilterConfig - the filter configinitpublic javax.servlet.FilterConfig getFilterConfig()
FilterConfig for this filter.FilterConfig for this filterFilterConfig@InitParam(name="once-per-request") public void setOncePerRequest(boolean pOncePerRequest)
true),
or for each forward/include resource (false).
Called automatically from the init-method, with settings
from web.xml.pOncePerRequest - true if the filter should run only
once per requestoncePerRequestCopyright © 2018. All rights reserved.