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:
To use this filter, you must declare it in the
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).