During the lifetime of a typical Java EE web application, a number of events take place and the Servlet API provides listener interfaces that we can implement.

Introduction

In my previous article, Creating Filters With GServlet, we learned how to create filters with the GServlet API for an elegant implementation with the Groovy language. In this one, we are going to cover how to handle Servlet events. During the lifetime of a typical Java EE web application, a number of events take place and the Servlet API provides a number of listener interfaces that we can implement.

ServletContextListener

Interface for receiving notification events about ServletContext lifecycle changes.

ServletContextAttributeListener

Interface for receiving notification events about ServletContext attribute changes.

ServletRequestListener

Interface for receiving notification events about a ServletRequest coming into and going out of the scope of a web application.

ServletRequestAttributeListener

Interface for receiving notification events about ServletRequest attribute changes.

HttpSessionListener

Interface for receiving notification events about HttpSession lifecycle changes.

HttpSessionAttributeListener

Interface for receiving notification events about HttpSession attribute changes.

HttpSessionBindingListener

Interface for receiving notification events when an object is bound to or unbound from a HttpSession.

HttpSessionActivationListener

Interface for receiving notification events when an HttpSession is being passivated and and activated.

HttpSessionIdListener

Interface for receiving notification events about HttpSession id changes.

For a practical example showing how to react to these events with the GServlet API, we will first create a Maven war project.

#java #groovy #servlet #java tutorial #listeners #gservlet #interface definition language #listener interface

Handling Events With GServlet
1.15 GEEK