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.
Interface for receiving notification events about ServletContext lifecycle changes.
ServletContextAttributeListener
Interface for receiving notification events about ServletContext attribute changes.
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.
Interface for receiving notification events about HttpSession lifecycle changes.
Interface for receiving notification events about HttpSession attribute changes.
Interface for receiving notification events when an object is bound to or unbound from a HttpSession.
Interface for receiving notification events when an HttpSession is being passivated and and activated.
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