Top Description Constructors Methods
javax.servlet.http

public abstract Class HttpFilter

extends GenericFilter
Class Inheritance
Imports
java.io.IOException, javax.servlet.FilterChain, .GenericFilter, .ServletException, .ServletRequest, .ServletResponse

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.

Author
Various
Since
Servlet 4.0

Constructor Summary

AccessConstructor and Description
public
HttpFilter()

Does nothing, because this is an abstract class.

Method Summary

Modifier and TypeMethod and Description
public void
doFilter(ServletRequest
a ServletRequest object that contains the request the client has made of the filter
req
,
ServletResponse
a ServletResponse object that contains the response the filter sends to the client
res
,
FilterChain
the FilterChain for invoking the next filter or the resource
chain
)

Implements javax.servlet.Filter.doFilter.

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 void
doFilter(HttpServletRequest
a HttpServletRequest object that contains the request the client has made of the filter
req
,
HttpServletResponse
a HttpServletResponse object that contains the response the filter sends to the client
res
,
FilterChain
the FilterChain for invoking the next filter or the resource
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.

Inherited from javax.servlet.GenericFilter:
getFilterConfiggetFilterNamegetInitParametergetInitParameterNamesgetServletContextinitinit

Constructor Detail

HttpFilterback to summary
public HttpFilter()

Does nothing, because this is an abstract class.

Since
4.0

Method Detail

doFilterback to summary
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException

Implements javax.servlet.Filter.doFilter.

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.

Parameters
req:ServletRequest

a ServletRequest object that contains the request the client has made of the filter

res:ServletResponse

a ServletResponse object that contains the response the filter sends to the client

chain:FilterChain

the FilterChain for invoking the next filter or the resource

Annotations
@Override
Exceptions
IOException:
if an input or output error is detected when the filter handles the request
ServletException:
if the request for the could not be handled or either parameter is not an instance of the respective HttpServletRequest or HttpServletResponse.
Since
Servlet 4.0
doFilterback to summary
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

Parameters
req:HttpServletRequest

a HttpServletRequest object that contains the request the client has made of the filter

res:HttpServletResponse

a HttpServletResponse object that contains the response the filter sends to the client

chain:FilterChain

the FilterChain for invoking the next filter or the resource

Exceptions
IOException:
if an input or output error is detected when the filter handles the request
ServletException:
if the request for the could not be handled
Since
Servlet 4.0