Package jakarta.servlet
Class GenericFilter
java.lang.Object
jakarta.servlet.GenericFilter
- All Implemented Interfaces:
Filter
,FilterConfig
,Serializable
- Direct Known Subclasses:
HttpFilter
Provides a base class that implements the Filter and FilterConfig interfaces to reduce boilerplate when writing new
filters.
- Since:
- Servlet 4.0
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionObtain the FilterConfig used to initialise this Filter instance.Get the name of the filter.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 the caller is executing.void
init()
Convenience method for sub-classes to save them having to callsuper.init(config)
.void
init
(FilterConfig filterConfig) Called by the web container to indicate to a filter that it is being placed into service.
-
Constructor Details
-
GenericFilter
public GenericFilter()
-
-
Method Details
-
getInitParameter
Description copied from interface:FilterConfig
Returns aString
containing the value of the named initialization parameter, ornull
if the parameter does not exist.- Specified by:
getInitParameter
in interfaceFilterConfig
- Parameters:
name
-String
specifying the name of the initialization parameter- Returns:
String
containing the value of the initialization parameter
-
getInitParameterNames
Description copied from interface:FilterConfig
Returns the names of the filter's initialization parameters as anEnumeration
ofString
objects, or an emptyEnumeration
if the filter has no initialization parameters.- Specified by:
getInitParameterNames
in interfaceFilterConfig
- Returns:
Enumeration
ofString
objects containing the names of the filter's initialization parameters
-
getFilterConfig
Obtain the FilterConfig used to initialise this Filter instance.- Returns:
- The config previously passed to the
init(FilterConfig)
method
-
getServletContext
Description copied from interface:FilterConfig
Returns a reference to theServletContext
in which the caller is executing.- Specified by:
getServletContext
in interfaceFilterConfig
- Returns:
ServletContext
object, used by the caller to interact with its servlet container- See Also:
-
init
Description copied from interface:Filter
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
- Specified by:
init
in interfaceFilter
- Parameters:
filterConfig
- The configuration information associated with the filter instance being initialised- Throws:
ServletException
- if the initialisation fails
-
init
Convenience method for sub-classes to save them having to callsuper.init(config)
. This is a NO-OP by default.- Throws:
ServletException
- If an exception occurs that interrupts the Filter's normal operation
-
getFilterName
Description copied from interface:FilterConfig
Get the name of the filter.- Specified by:
getFilterName
in interfaceFilterConfig
- Returns:
- The filter-name of this filter as defined in the deployment descriptor.
-