What is Servlet Filter and how does it work?

What is Servlet Filter and how does it work?

Filters are powerful tools in servlet environment. Filters add certain functionality to the servlets apart from processing request and response paradigm of servlet processing. Filters manipulate the request and response in a web application, and they can be applied to any resources like HTML, graphics, a JSP page which are served by the servlet engine. Authentication of data, format conversion of data and redirecting the page to another page are certain useful functions of filters.

A filter is configured in a web.xml file. The class using the filters should extend javax.servlet.Filter. Every request in a web application, the servlet container decides the filters to apply and adds them to the filter chain, in the order they appear in web.xml file. A filter also has life cycle mechanisms init(),doFilter() and destroy().
Explain the use of logic:iterate tag in struts application
The tag is utilized for repeating the nested body content over a collection. Every element / object in a specified collection...
Difference between DataInputStream and BufferedReader
The differences are: The DataInputStream works with the binary data, while the BufferedReader work with character data...
Difference between throw and throws - Java
The throw key word is used to explicitly throw an exception, while throws is utilized to handle checked exceptions for re-intimating the compiler that exceptions are being handled...
Post your comment
Discussion Board
Another point
Another point about filters is that they create a chain when the same url pattern is used for multiple filters. We need to call filter.doChain method
Java EE filter
About Java EE Filters 01-16-2013