Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of a listener class in a large project

I'm confused about what listener classes do. For example, in this project there is a listener class referenced as so:

<listener>
    <listener-class>com.sun.javaee.blueprints.petstore.model.CatalogFacade</listener-class> 
</listener>

Is it as the name implies, just listening for actions to do?

like image 962
Caffeinated Avatar asked Sep 22 '11 06:09

Caffeinated


1 Answers

Listener Classes get notified on selected events, such as starting up the application or creating a new Session.

Listener Classes :

These are simple Java classes which implement one of the two following interfaces :

  • javax.servlet.ServletContextListener
  • javax.servlet.http.HttpSessionListener

If you want your class to listen for application startup and shutdown events then implement ServletContextListener interface. If you want your class to listen for session creation and invalidation events then implement HttpSessionListener interface.

Source

like image 65
Pål Brattberg Avatar answered Sep 20 '22 16:09

Pål Brattberg