public abstract class HttpFilter extends GenericFilter
Provides an abstract class to be subclassed to create
an HTTP filter suitable for a Web site. A subclass of
HttpFilter
should override doFilter(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.FilterChain)
.
Filters typically run on multithreaded servers, so be aware that a filter must handle concurrent requests and be careful to synchronize access to shared resources. Shared resources include in-memory data such as instance or class variables and external objects such as files, database connections, and network connections. See the Java Tutorial on Multithreaded Programming for more information on handling multiple threads in a Java program.
Constructor and Description |
---|
HttpFilter()
Does nothing, because this is an abstract class.
|
Modifier and Type | Method and Description |
---|---|
protected void |
doFilter(HttpServletRequest req,
HttpServletResponse res,
FilterChain chain)
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. |
void |
doFilter(ServletRequest req,
ServletResponse res,
FilterChain chain)
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. |
getFilterConfig, getFilterName, getInitParameter, getInitParameterNames, getServletContext, init, init
public HttpFilter()
Does nothing, because this is an abstract class.
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException
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.
The FilterChain passed in to this method allows the Filter to pass
on the request and response to the next entity in the chain. There's no need to
override this method.
The default implementation inspects the incoming req
and res
objects to determine if they are instances of HttpServletRequest
and HttpServletResponse
, respectively. If not, a ServletException
is thrown.
Otherwise, the protected doFilter(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.FilterChain)
method is called.
req
- a ServletRequest
object that
contains the request the client has made
of the filterres
- a ServletResponse
object that
contains the response the filter sends
to the clientchain
- the FilterChain
for invoking the next filter or the resourceIOException
- if an input or output error is
detected when the filter handles
the requestServletException
- if the request for the could not be handled or
either parameter is not an instance of the respective HttpServletRequest
or HttpServletResponse
.UnavailableException
protected void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws IOException, ServletException
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.
The FilterChain passed in to this method allows the Filter to pass
on the request and response to the next entity in the chain.
The default implementation simply calls FilterChain.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
req
- a HttpServletRequest
object that
contains the request the client has made
of the filterres
- a HttpServletResponse
object that
contains the response the filter sends
to the clientchain
- the FilterChain
for invoking the next filter or the resourceIOException
- if an input or output error is
detected when the filter handles
the requestServletException
- if the request for the could not be handledCopyright © 1996-2017, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.