Servlet Filter
Servlet Listener
Servlet Filter is used for monitoring request and response from client to the servlet, or to modify the request and response, or to audit and log.
Servlet Listener is used for listening to events in a web containers, such as when you create a session, or place an attribute in an session or if you passivate and activate in another container, to subscribe to these events you can configure listener in web.xml, for example HttpSessionListener.
Filter is an object which transform the request and response (header as well as content).
You can monitor and react to events in a servlet’s life cycle by defining listener objects whose methods get invoked when life cycle events occur.
Filters are used for pre and post process requests. Look at the javax.servlet.Filter in your tomcat/jboss/other container javadoc.
Where as the listeners are like triggers that can be attached to events in your app server (let’s use the term container here). With listeners you can track application-level, session-level, life-cycle changes, attribute changes etc. The implemented interfaces are javax.servlet.Listener interface.
Filters work with servlet container dispatches. For one listener invocation there may be multiple filters/servlet invocations. Filters implement javax.servlet.Filter
While listeners get triggered for an actual physical request listeners implements javax.servlet.ServletContextListener and other listed listeners.
Categories: Java

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Apache Ant

Apache Ant basic tasks

In the previous post, we have learned what is Apache Ant, its features and an example to create simple build file.¬†This post will guide you other basic ant tasks that are frequently used to create Read more…

Apache Ant

Apache Ant : Java Build Tool

Apache Ant is a Java library and command-line tool to automate the repetitive tasks and helps to build software.¬†Ant is flexible and does not impose coding conventions. It supplies a number of built-in tasks allowing Read more…


Advantages of spring interceptor over servlet filter

Even filters can do the same things that interceptors can but interceptors can do more easily and more elegantly. Interceptors are more coupled to the request/response cycle than filters. Can inject other beans in the Read more…