Filter vs. RequestDispatcher
1 posts in topic
Flat View  Flat View

Posted By:   A_E
Posted On:   Wednesday, September 11, 2002 07:44 PM

My question is, what is the practical difference between a Filter and a RequestDispatcher?

I'm aware that you can build a filter chain and specify the chain in your web.xml, but you could "roll your own" dynamic solution for RequestDispatchers. Are they implemented differently, or is a Filter really just a servlet with an extra parameter that calls a RequestDispatcher behind the scenes? What are the advatages/disadvantages of each?

Re: Filter vs. RequestDispatcher

Posted By:   AlessandroA_Garbagnati  
Posted On:   Thursday, September 12, 2002 01:25 AM


Fiters can be considered a special type of servlet, but their purpose is different of just allowing chainging through a RequestDispatcher call behind the scene.

A filter is called before and after one (or more) servlet or JSP. The idea behind it was to provide a system that allows developers to access to the request and response object before the start and after the end of the process.

Like Tomcat 3.x interceptors, Filters allow the developers to make changes to the request object or even the response object. For example, you can change the "output" of a servlet/JSP, sending it or to a file or even to both file and client...

RequestDispatcher is only a mechanism to pass the control to another servlet (or JSP, is the same thing), temporary (include) or completely (forward).

About | Sitemap | Contact