0 votes
2.6k views
in Java by
What is the difference between filter and listener ?

1 Answer

0 votes
by
There are following difference between filter and listener:-

1) Filters are used for pre and post process requests. If you want to craete filter then you must be implements javax.servlet.Filter interface.
Listeners are like triggers that can be attached to events in your app server. With listeners you can track application-level, session-level, life-cycle changes, attribute changes etc. If you want to craete listeners then you must be implement interfaces are javax.servlet.Listener interface.

2) Servlet Filter is used to monitor the request and response from client to the servlet, or modify the request and response.
Servlet Listener is used to listen 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.

3) Filter is simply Filtering the response and request coming from the clients to the servlet.
Listener is like a trigger when any trigger is occur it take the action.

4) Filter is used for the Servlet, it is intercepting the requests and responses.
Listener is used for the Web Application, it is doing important tasks on events in context-level, session-level etc.

Share:- Whatsapp Facebook Facebook


Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

Categories

...