Configuring filter in web.xml

Configuring filter in web.xml


Posted in : Servlet Posted on : December 1, 2010 at 6:38 PM Comments : [ 0 ]

This section contains the details about Configuring filter in web.xml.

Configuring filter in web.xml

This section contains the detail about how to configure web.xml file. As we discuss in earlier section that filters process request before it reaches to a servlet and can process response before it leaves to a servlet.

First, you need to code the filter before configuring it to web.xml file. For code example Click on given below link:

http://www.devmanuals.com/tutorials/java/servlet/ServletFilters.html

To use this filter, you must declare it in the web.xml deployment descriptor using the <filter>tag, as shown below :

<filter>
<filter-name>FilterDemo</filter-name>
<filter-class>FilterDemo</filter-class>
</filter>

This tells the server that a filter of name "FilterDemo" is implemented in "FilterDemo" class. You can apply a filter to certain URL patterns or servlet names using the <filter-mapping> tag : 

<filter-mapping>
<filter-name>FilterDemo</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

The above url-pattern configure the filter to all the requests to the server (static or dynamic).

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics