Servlet FilterConfig

Google Advertisements

Prev Tutorial Next Tutorial

FilterConfig in Servlet

We can define filter same as Servlet. Let's see the elements of filter and filter-mapping.

Servlet FilterConfig Example


<web-app>

<filter>
<filter-name>...</filter-name>
<filter-class>...</filter-class>
</filter>
 
<filter-mapping>
<filter-name>...</filter-name>
<url-pattern>...</url-pattern>
</filter-mapping>

</web-app>

For mapping filter we can use, either url-pattern or Servlet-name. The url-pattern elements has an advantage over Servlet-name element i.e. it can be applied on servlet, JSP or HTML.

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.

  • public void init(FilterConfig config): init() method is invoked only once it is used to initialize the filter.
  • public String getInitParameter(String parameterName): Returns the parameter value for the specified parameter name.
  • public java.util.Enumeration getInitParameterNames(): Returns an enumeration containing all the parameter names.
  • 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

Prev Tutorial Next Tutorial

Google Advertisements

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483 Try this Keyword C++ Programs