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
Imports
java.util.Enumeration, .ResourceBundle

Defines a generic, protocol-independent filter. To write an HTTP filter for use on the Web, extend jakarta.servlet.http.HttpFilter instead.

GenericFilter implements the Filter and FilterConfig interfaces. GenericFilter may be directly extended by a filter, although it's more common to extend a protocol-specific subclass such as HttpFilter.

GenericFilter makes writing filters easier. It provides simple versions of the lifecycle methods init and destroy and of the methods in the FilterConfig interface.

To write a generic filter, you need only override the abstract doFilter method.

Author
Various
Since
Servlet 4.0

Field Summary

Modifier and TypeField and Description
private transient FilterConfig
private static final String
private static final ResourceBundle
private static final long

Constructor Summary

AccessConstructor and Description
public
GenericFilter()

Does nothing.

Method Summary

Modifier and TypeMethod and Description
public FilterConfig

Returns:

FilterConfig the FilterConfig object that initialized this filter
getFilterConfig
()

Returns this servlet's ServletConfig object.

public String

Returns:

the name of this filter instance
getFilterName
()

Implements jakarta.servlet.FilterConfig.getFilterName.

Returns the name of this filter instance.

public String

Returns:

String a String containing the value of the initialization parameter
getInitParameter
(String
a 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>

Returns:

Enumeration an enumeration of String objects containing the names of the filter's initialization parameters
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

Returns:

ServletContext the ServletContext object passed to this filter by the init method
getServletContext
()

Implements jakarta.servlet.FilterConfig.getServletContext.

Returns a reference to the ServletContext in which this filter is running.

public void
init(FilterConfig
the FilterConfig object that contains configuration information for this filter
config
)

Overrides default jakarta.servlet.Filter.init.

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

public void
init()

A convenience method which can be overridden so that there's no need to call super.init(config).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

configback to summary
private transient FilterConfig config
LSTRING_FILEback to summary
private static final String LSTRING_FILE
lStringsback to summary
private static final ResourceBundle lStrings
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

GenericFilterback to summary
public GenericFilter()

Does nothing. All of the filter initialization is done by one of the init methods.

Since
Servlet 4.0

Method Detail

getFilterConfigback to summary
public FilterConfig getFilterConfig()

Returns this servlet's ServletConfig object.

Returns:FilterConfig

FilterConfig the FilterConfig object that initialized this filter

Since
Servlet 4.0
getFilterNameback to summary
public String getFilterName()

Implements jakarta.servlet.FilterConfig.getFilterName.

Returns the name of this filter instance. See FilterConfig#getFilterName.

Returns:String

the name of this filter instance

Annotations
@Override
Since
Servlet 4.0
getInitParameterback to summary
public String getInitParameter(String 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. See FilterConfig#getInitParameter.

This method is supplied for convenience. It gets the value of the named parameter from the servlet's ServletConfig object.

Parameters
name:String

a String specifying the name of the initialization parameter

Returns:String

String a String containing the value of the initialization parameter

Annotations
@Override
Since
Servlet 4.0
getInitParameterNamesback to summary
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. See FilterConfig#getInitParameterNames.

This method is supplied for convenience. It gets the parameter names from the filter's FilterConfig object.

Returns:Enumeration<String>

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

Annotations
@Override
Since
Servlet 4.0
getServletContextback to summary
public ServletContext getServletContext()

Implements jakarta.servlet.FilterConfig.getServletContext.

Returns a reference to the ServletContext in which this filter is running. See FilterConfig#getServletContext.

This method is supplied for convenience. It gets the context from the filter's FilterConfig object.

Returns:ServletContext

ServletContext the ServletContext object passed to this filter by the init method

Annotations
@Override
Since
Servlet 4.0
initback to summary
public void init(FilterConfig config) throws ServletException

Overrides default jakarta.servlet.Filter.init.

Called by the servlet container to indicate to a filter that it is being placed into service. See Filter#init.

This implementation stores the FilterConfig object it receives from the servlet container for later use. When overriding this form of the method, call super.init(config).

Parameters
config:FilterConfig

the FilterConfig object that contains configuration information for this filter

Annotations
@Override
Exceptions
ServletException:
if an exception occurs that interrupts the servlet's normal operation
Since
Servlet 4.0
See Also
UnavailableException
initback to summary
public void init() throws ServletException

A convenience method which can be overridden so that there's no need to call super.init(config).

Instead of overriding init(FilterConfig), simply override this method and it will be called by GenericFilter.init(FilterConfig config). The FilterConfig object can still be retrieved via getFilterConfig.

Exceptions
ServletException:
if an exception occurs that interrupts the servlet's normal operation
Since
Servlet 4.0