Class HttpFilter
- java.lang.Object
-
- jakarta.servlet.GenericFilter
-
- jakarta.servlet.http.HttpFilter
-
- All Implemented Interfaces:
Filter
,FilterConfig
,Serializable
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 overridedoFilter(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse, jakarta.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.
- Since:
- Servlet 4.0
- Author:
- Various
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description HttpFilter()
Does nothing, because this is an abstract class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain)
ThedoFilter
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)
ThedoFilter
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.-
Methods inherited from class jakarta.servlet.GenericFilter
getFilterConfig, getFilterName, getInitParameter, getInitParameterNames, getServletContext, init, init
-
-
-
-
Method Detail
-
doFilter
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
andres
objects to determine if they are instances ofHttpServletRequest
andHttpServletResponse
, respectively. If not, aServletException
is thrown. Otherwise, the protecteddoFilter(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse, jakarta.servlet.FilterChain)
method is called.- Parameters:
req
- aServletRequest
object that contains the request the client has made of the filterres
- aServletResponse
object that contains the response the filter sends to the clientchain
- theFilterChain
for invoking the next filter or the resource- Throws:
IOException
- 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 respectiveHttpServletRequest
orHttpServletResponse
.- Since:
- Servlet 4.0
- See Also:
UnavailableException
-
doFilter
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(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse)
- Parameters:
req
- aHttpServletRequest
object that contains the request the client has made of the filterres
- aHttpServletResponse
object that contains the response the filter sends to the clientchain
- theFilterChain
for invoking the next filter or the resource- Throws:
IOException
- if an input or output error is detected when the filter handles the requestServletException
- if the request for the could not be handled- Since:
- Servlet 4.0
-
-