In this article, we will see how to use event listeners in Java web programming.
With event listener, we can create our custom event driven code executions in web application.
ServletContextListener is the interface that gets informed about ServletContext lifecycle changes.
Lets see it in an example:
@WebListener
public class AppListener implements ServletContextListener
{
....
Lets see it in a java example.
In above example, we created our AppListener class and inherit it from ServletContextListener. We log some message for test our event listener work. Note that, we this time not placed our listener in web.xml, but did it with web annotation.