Top Description Fields Constructors Methods
jakarta.servlet

public abstract Class GenericFilter

extends Object
implements Filter, FilterConfig, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, jakarta.servlet.FilterConfig, jakarta.servlet.Filter
Known Direct Subclasses
jakarta.servlet.http.HttpFilter, org.apache.catalina.filters.CorsFilter, org.apache.catalina.filters.RateLimitFilter, org.apache.catalina.filters.RemoteIpFilter, org.apache.catalina.filters.RequestDumperFilter, org.apache.catalina.filters.WebdavFixFilter
Imports
java.io.Serializable, java.util.Enumeration

Provides a base class that implements the Filter and FilterConfig interfaces to reduce boilerplate when writing new filters.
Since
Servlet 4.0
See Also
jakarta.servlet.Filter, jakarta.servlet.FilterConfig

Field Summary

Modifier and TypeField and Description
private volatile FilterConfig
filterConfig

The filter configuration.

private static final long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public FilterConfig

Returns:

The config previously passed to the init(FilterConfig) method
getFilterConfig
()

Obtain the FilterConfig used to initialise this Filter instance.

public String
getFilterName()

Implements jakarta.servlet.FilterConfig.getFilterName.

Get the name of the filter.

public String
getInitParameter(String
String specifying the name of the initialization parameter
name
)

Implements jakarta.servlet.FilterConfig.getInitParameter.

Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist.

public Enumeration<String>
getInitParameterNames()

Implements jakarta.servlet.FilterConfig.getInitParameterNames.

Returns the names of the filter's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the filter has no initialization parameters.

public ServletContext
getServletContext()

Implements jakarta.servlet.FilterConfig.getServletContext.

Returns a reference to the ServletContext in which the caller is executing.

public void
init(FilterConfig
The configuration information associated with the filter instance being initialised
filterConfig
)

Overrides default jakarta.servlet.Filter.init.

Called by the web container to indicate to a filter that it is being placed into service.

public void
init()

Convenience method for sub-classes to save them having to call super.init(config).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

filterConfigback to summary
private volatile FilterConfig filterConfig

The filter configuration.

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

GenericFilterback to summary
public GenericFilter()

Method Detail

getFilterConfigback to summary
public FilterConfig getFilterConfig()

Obtain the FilterConfig used to initialise this Filter instance.

Returns:FilterConfig

The config previously passed to the init(FilterConfig) method

getFilterNameback to summary
public String getFilterName()

Implements jakarta.servlet.FilterConfig.getFilterName.

Doc from jakarta.servlet.FilterConfig.getFilterName.

Get the name of the filter.

Returns:String

The filter-name of this filter as defined in the deployment descriptor.

Annotations
@Override
getInitParameterback to summary
public String getInitParameter(String name)

Implements jakarta.servlet.FilterConfig.getInitParameter.

Doc from jakarta.servlet.FilterConfig.getInitParameter.

Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist.

Parameters
name:String

String specifying the name of the initialization parameter

Returns:String

String containing the value of the initialization parameter

Annotations
@Override
getInitParameterNamesback to summary
public Enumeration<String> getInitParameterNames()

Implements jakarta.servlet.FilterConfig.getInitParameterNames.

Doc from jakarta.servlet.FilterConfig.getInitParameterNames.

Returns the names of the filter's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the filter has no initialization parameters.

Returns:Enumeration<String>

Enumeration of String objects containing the names of the filter's initialization parameters

Annotations
@Override
getServletContextback to summary
public ServletContext getServletContext()

Implements jakarta.servlet.FilterConfig.getServletContext.

Doc from jakarta.servlet.FilterConfig.getServletContext.

Returns a reference to the ServletContext in which the caller is executing.

Returns:ServletContext

ServletContext object, used by the caller to interact with its servlet container

Annotations
@Override
initback to summary
public void init(FilterConfig filterConfig) throws ServletException

Overrides default jakarta.servlet.Filter.init.

Doc from jakarta.servlet.Filter.init.

Called by the web container to indicate to a filter that it is being placed into service. The servlet container calls the init method exactly once after instantiating the filter. The init method must complete successfully before the filter is asked to do any filtering work.

The web container cannot place the filter into service if the init method either:

  • Throws a ServletException
  • Does not return within a time period defined by the web container
The default implementation is a NO-OP.
Parameters
filterConfig:FilterConfig

The configuration information associated with the filter instance being initialised

Annotations
@Override
Exceptions
ServletException:
if the initialisation fails
initback to summary
public void init() throws ServletException

Convenience method for sub-classes to save them having to call super.init(config). This is a NO-OP by default.

Exceptions
ServletException:
If an exception occurs that interrupts the Filter's normal operation