Filters

Sarath Soman

Filters are components that can be used to pre process the request and post process the response. Filters are useful in separating the cross cutting concerns like Security, logging.
Developers will be implementing the Filter Interface provided with the Servlet Api. Like Servlets mapped towards urls using annotation Filters can be mapped towards urls and Servlet names with annotation or via configuration in web.xml or by mixing both.
Life cycle of the Filter is same as the Servlet life cycle except that container will be calling the doFilter() provided by the Filter interface. A filter will be having one instance per declaration and like ServletConfig there will be a FilterConfig object injected inside it. (FilterConfig holds the reference to ServletContext).

filter

I think filters works more like the Decorater Pattern. A filter can be mapped to any number of servlets or urls. Also a Servlets can have any number of Filters…

View original post 411 mots de plus

Publicités
Par défaut