- All Implemented Interfaces:
Filter
,FilterConfig
,Serializable
- Direct Known Subclasses:
HttpFilter
Defines a generic, protocol-independent filter. To write an HTTP filter for use on the Web, extend
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.
- Since:
- Servlet 4.0
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns this servlet'sServletConfig
object.Returns the name of this filter instance.getInitParameter
(String name) Returns aString
containing the value of the named initialization parameter, ornull
if the parameter does not exist.Returns the names of the filter's initialization parameters as anEnumeration
ofString
objects, or an emptyEnumeration
if the filter has no initialization parameters.Returns a reference to theServletContext
in which this filter is running.void
init()
A convenience method which can be overridden so that there's no need to callsuper.init(config)
.void
init
(FilterConfig config) Called by the servlet container to indicate to a filter that it is being placed into service.
-
Constructor Details
-
GenericFilter
public GenericFilter()Does nothing. All of the filter initialization is done by one of the
init
methods.- Since:
- Servlet 4.0
-
-
Method Details
-
getInitParameter
Returns a
String
containing the value of the named initialization parameter, ornull
if the parameter does not exist. SeeFilterConfig.getInitParameter(java.lang.String)
.This method is supplied for convenience. It gets the value of the named parameter from the servlet's
ServletConfig
object.- Specified by:
getInitParameter
in interfaceFilterConfig
- Parameters:
name
- aString
specifying the name of the initialization parameter- Returns:
- String a
String
containing the value of the initialization parameter - Since:
- Servlet 4.0
-
getInitParameterNames
Returns the names of the filter's initialization parameters as an
Enumeration
ofString
objects, or an emptyEnumeration
if the filter has no initialization parameters. SeeFilterConfig.getInitParameterNames()
.This method is supplied for convenience. It gets the parameter names from the filter's
FilterConfig
object.- Specified by:
getInitParameterNames
in interfaceFilterConfig
- Returns:
- Enumeration an enumeration of
String
objects containing the names of the filter's initialization parameters - Since:
- Servlet 4.0
-
getFilterConfig
Returns this servlet's
ServletConfig
object.- Returns:
- FilterConfig the
FilterConfig
object that initialized this filter - Since:
- Servlet 4.0
-
getServletContext
Returns a reference to the
ServletContext
in which this filter is running. SeeFilterConfig.getServletContext()
.This method is supplied for convenience. It gets the context from the filter's
FilterConfig
object.- Specified by:
getServletContext
in interfaceFilterConfig
- Returns:
- ServletContext the
ServletContext
object passed to this filter by theinit
method - Since:
- Servlet 4.0
- See Also:
-
init
Called by the servlet container to indicate to a filter that it is being placed into service. See
Filter.init(jakarta.servlet.FilterConfig)
.This implementation stores the
FilterConfig
object it receives from the servlet container for later use. When overriding this form of the method, callsuper.init(config)
.- Specified by:
init
in interfaceFilter
- Parameters:
config
- theFilterConfig
object that contains configuration information for this filter- Throws:
ServletException
- if an exception occurs that interrupts the servlet's normal operation- Since:
- Servlet 4.0
- See Also:
-
init
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 byGenericFilter.init(FilterConfig config)
. TheFilterConfig
object can still be retrieved viagetFilterConfig()
.- Throws:
ServletException
- if an exception occurs that interrupts the servlet's normal operation- Since:
- Servlet 4.0
-
getFilterName
Returns the name of this filter instance. See
FilterConfig.getFilterName()
.- Specified by:
getFilterName
in interfaceFilterConfig
- Returns:
- the name of this filter instance
- Since:
- Servlet 4.0
-