Monday, July 9, 2018

ServletContextEvent and ServletContextListener


  • 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. 

Constructor of ServletContextEvent class
  1. ServletContextEvent(ServletContext source): Construct a ServletRequestEvent for the given ServletContext and ServletRequest.

Methods of ServletContextEvent class
  1.  public ServletContext getServletContext(): Returns the instance of ServletContext.
Methods of ServletContextListener interface
  1. public void contextInitialized(ServletContextEvent e): is invoked when application is deployed on the server.
  2. public void contextDestroyed(ServletContextEvent e): is invoked when application is undeployed from the server.

No comments:

Post a Comment