Class GenericFilter
- java.lang.Object
-
- jakarta.servlet.GenericFilter
-
- All Implemented Interfaces:
Filter,FilterConfig,Serializable
- Direct Known Subclasses:
HttpFilter
public abstract class GenericFilter extends Object implements Filter, FilterConfig, Serializable
Defines a generic, protocol-independent filter. To write an HTTP filter for use on the Web, extend
HttpFilterinstead.GenericFilterimplements theFilterandFilterConfiginterfaces.GenericFiltermay be directly extended by a filter, although it's more common to extend a protocol-specific subclass such asHttpFilter.GenericFiltermakes writing filters easier. It provides simple versions of the lifecycle methodsinitanddestroyand of the methods in theFilterConfiginterface.To write a generic filter, you need only override the abstract
doFiltermethod.- Since:
- Servlet 4.0
- Author:
- Various
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description GenericFilter()Does nothing.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FilterConfiggetFilterConfig()Returns this servlet'sServletConfigobject.StringgetFilterName()Returns the name of this filter instance.StringgetInitParameter(String name)Returns aStringcontaining the value of the named initialization parameter, ornullif the parameter does not exist.Enumeration<String>getInitParameterNames()Returns the names of the filter's initialization parameters as anEnumerationofStringobjects, or an emptyEnumerationif the filter has no initialization parameters.ServletContextgetServletContext()Returns a reference to theServletContextin which this filter is running.voidinit()A convenience method which can be overridden so that there's no need to callsuper.init(config).voidinit(FilterConfig config)Called by the servlet container to indicate to a filter that it is being placed into service.
-
-
-
Method Detail
-
getInitParameter
public String getInitParameter(String name)
Returns a
Stringcontaining the value of the named initialization parameter, ornullif 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
ServletConfigobject.- Specified by:
getInitParameterin interfaceFilterConfig- Parameters:
name- aStringspecifying the name of the initialization parameter- Returns:
- String a
Stringcontaining the value of the initialization parameter - Since:
- Servlet 4.0
-
getInitParameterNames
public Enumeration<String> getInitParameterNames()
Returns the names of the filter's initialization parameters as an
EnumerationofStringobjects, or an emptyEnumerationif the filter has no initialization parameters. SeeFilterConfig.getInitParameterNames().This method is supplied for convenience. It gets the parameter names from the filter's
FilterConfigobject.- Specified by:
getInitParameterNamesin interfaceFilterConfig- Returns:
- Enumeration an enumeration of
Stringobjects containing the names of the filter's initialization parameters - Since:
- Servlet 4.0
-
getFilterConfig
public FilterConfig getFilterConfig()
Returns this servlet's
ServletConfigobject.- Returns:
- FilterConfig the
FilterConfigobject that initialized this filter - Since:
- Servlet 4.0
-
getServletContext
public ServletContext getServletContext()
Returns a reference to the
ServletContextin which this filter is running. SeeFilterConfig.getServletContext().This method is supplied for convenience. It gets the context from the filter's
FilterConfigobject.- Specified by:
getServletContextin interfaceFilterConfig- Returns:
- ServletContext the
ServletContextobject passed to this filter by theinitmethod - Since:
- Servlet 4.0
- See Also:
ServletContext
-
init
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(jakarta.servlet.FilterConfig).This implementation stores the
FilterConfigobject it receives from the servlet container for later use. When overriding this form of the method, callsuper.init(config).- Specified by:
initin interfaceFilter- Parameters:
config- theFilterConfigobject 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:
UnavailableException
-
init
public void init() throws ServletExceptionA 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). TheFilterConfigobject can still be retrieved viagetFilterConfig().- Throws:
ServletException- if an exception occurs that interrupts the servlet's normal operation- Since:
- Servlet 4.0
-
getFilterName
public String getFilterName()
Returns the name of this filter instance. See
FilterConfig.getFilterName().- Specified by:
getFilterNamein interfaceFilterConfig- Returns:
- the name of this filter instance
- Since:
- Servlet 4.0
-
-