public abstract class GenericFilter extends java.lang.Object implements Filter, FilterConfig, java.io.Serializable
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.
Constructor and Description |
---|
GenericFilter()
Does nothing.
|
Modifier and Type | Method and Description |
---|---|
FilterConfig |
getFilterConfig()
Returns this servlet's
ServletConfig object. |
java.lang.String |
getFilterName()
Returns the name of this filter instance.
|
java.lang.String |
getInitParameter(java.lang.String name)
Returns a
String containing the value of the named initialization parameter, or null if
the parameter does not exist. |
java.util.Enumeration<java.lang.String> |
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. |
ServletContext |
getServletContext()
Returns a reference to the
ServletContext in which this filter is running. |
void |
init()
A convenience method which can be overridden so that there's no need to call
super.init(config) . |
void |
init(FilterConfig config)
Called by the servlet container to indicate to a filter that it is being placed into service.
|
public GenericFilter()
Does nothing. All of the filter initialization is done by one of the init
methods.
public java.lang.String getInitParameter(java.lang.String name)
Returns a String
containing the value of the named initialization parameter, or null
if
the parameter does not exist. See FilterConfig.getInitParameter(java.lang.String)
.
This method is supplied for convenience. It gets the value of the named parameter from the servlet's
ServletConfig
object.
getInitParameter
in interface FilterConfig
name
- a String
specifying the name of the initialization parameterString
containing the value of the initialization parameterpublic java.util.Enumeration<java.lang.String> 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.
getInitParameterNames
in interface FilterConfig
String
objects containing the names of the filter's
initialization parameterspublic FilterConfig getFilterConfig()
Returns this servlet's ServletConfig
object.
FilterConfig
object that initialized this filterpublic ServletContext 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.
getServletContext
in interface FilterConfig
ServletContext
object passed to this filter by the init
methodServletContext
public void init(FilterConfig config) throws ServletException
Called by the servlet container to indicate to a filter that it is being placed into service. See
Filter.init(javax.servlet.FilterConfig)
.
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)
.
init
in interface Filter
config
- the FilterConfig
object that contains configuration information for this filterServletException
- if an exception occurs that interrupts the servlet's normal operationUnavailableException
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()
.
ServletException
- if an exception occurs that interrupts the servlet's normal operationpublic java.lang.String getFilterName()
Returns the name of this filter instance. See FilterConfig.getFilterName()
.
getFilterName
in interface FilterConfig