...

View Full Version : Filter



otnj2ee
02-20-2008, 08:50 PM
In the web.xml, there is a filter section, such as:


<filter>
<filter-name>TestFilter</filter-name>
<filter-class>com.test.TestFilter</filter-class>
</filter>


--Why do we need filter? or, under what circumstances should I use filter otherthan other class?

(Seems like I can use the servlet mapping to achieve the same)


Thanks


Scott

sobrien79
02-20-2008, 10:43 PM
From how I understand it, a servlet is specific to a url.

http://www.example.com/myServlet

Hitting that url will run that servlet. Generally a whole web page is output.

http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets2.html

As for filters, they provide specific bits of functionality without using page includes. An example might be that you want to inject certain content at the beginning and end of each page.

http://java.sun.com/products/servlet/Filters.html



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum