What is a filter and how do I use it?
Author: Deron Eriksson
Description: This tutorial describes filters and how to use them.
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 2.0 (Eclipse 3.3.0) || Tomcat 5.5.20


Page: < 1 2

(Continued from page 1)

I fired up the application in TomcatSW and made a request for the TestServlet via the /test mapping in web.xmlW. As you can see, the MyFilter class is executed, and in the 'Regular Content' section we can see the regular content served up by the servletW.

http://localhost:8080/filter-test/test

I added a couple parameter name/value pairs to the URL, and you can see that the filter displays the request parameters and their values.

http://localhost:8080/filter-test/test?a=b&c=d

As an additional test, I hit the index.jsp page and passed in a couple parameter name/value pairs on the URL, and you can once again see that the filter doFilter() method gets executed when index.jsp is requested by the browser.

http://localhost:8080/filter-test/index.jsp?e=f&g=h

As you can see, filters are a great of performing a set of functionality when a particular resource or set of resources is requested.

Page: < 1 2