Javatpoint Logo
Javatpoint Logo

FilterConfig

An object of FilterConfig is created by the web container. This object can be used to get the configuration information from the web.xml file.

Methods of FilterConfig interface

There are following 4 methods in the FilterConfig interface.

  1. public void init(FilterConfig config): init() method is invoked only once it is used to initialize the filter.
  2. public String getInitParameter(String parameterName): Returns the parameter value for the specified parameter name.
  3. public java.util.Enumeration getInitParameterNames(): Returns an enumeration containing all the parameter names.
  4. public ServletContext getServletContext(): Returns the ServletContext object.

Example of FilterConfig

In this example, if you change the param-value to no, request will be forwarded to the servlet otherwise filter will create the response with the message: this page is underprocessing. Let's see the simple example of FilterConfig. Here, we have created 4 files:

  • index.html
  • MyFilter.java
  • HelloServlet.java
  • web.xml
index.html

MyFilter.java

HelloServlet.java

web.xml




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA