07 Filter
07 Filter
------------------------------------------------------------------------------------------------------------------------------------------
A web request has to go through various conditions which determine whether the request can be processed or not.
These conditions have to be implemented programmatically. It is advisable to put such code out side the
component so that it can be reused and in case of any change, we need not touch the actual end target of the
request. This makes the code more manageable.
The pre and post processing components are implemented through Filter concept. There can be many filters thus
forming a Filter Chain.
Note: The earlier name of such concept was Servlet Chain since the individual components were Servlets. From
version 2.3 of Servlets a new concept called Filter Concept is implemented for implementing such pattern.
chain.doFilter(): will result in next component in the chain to be invoked. In the life time of a Filter this method
will invoke more than once depending on the URL pattern of the request.
Note: The Web Container maintains a single instance of each filter in the application and all the requests will end
up the same instance.
The more generic filter comes first and then the specific filter. If 2 filters are at the same level, then the order of
declaration will be used for constructing the chain.