Events are basically occurrence of something. Changing the state of an object is known as an event.
We can perform some important tasks at the occurrence of these exceptions, such as counting total and current logged-in users, creating tables of the database at time of deploying the project, creating database connection object etc.
- ServletRequestEvent
- ServletContextEvent
- ServletRequestAttributeEvent
- ServletContextAttributeEvent
- HttpSessionEvent
- HttpSessionBindingEvent
- ServletRequestListener
- ServletRequestAttributeListener
- ServletContextListener
- ServletContextAttributeListener
- HttpSessionListener
- HttpSessionAttributeListener
- HttpSessionBindingListener
- HttpSessionActivationListener
- The ServletContextEvent is notified when web application is deployed on the server.
- If you want to perform some action at the time of deploying the web application such as creating database connection, creating all the tables of the project etc, you need to implement ServletContextListener interface and provide the implementation of its methods.
Web application > ServletContextEvent > ServletContextListener
- The HttpSessionEvent is notified when session object is changed. The corresponding Listener interface for this event is HttpSessionListener.
- We can perform some operations at this event such as counting total and current logged-in users, maintaing a log of user details such as login time, logout time etc.
session object > HttpSessionEvent > HttpSessionListener