Chapter 06 - The Servlet Container Model

In this web application, we show the features of the servlet container model that allow you to specify the initialization parameters and listener interfaces for a web application.
  1. TestServlet displays all the application initialization parameters and their values on the browser. In the web.xml we have configured one initialization parameter using the following tags:
      <context-param>
         <param-name>dburl</param-name>
         <param-value>jdbc:odbc:MySQLODBC</param-value>
      </context-param>
    

    Try adding your own parameters in web.xml and see the result. Remember: You will have to restart Tomcat for the new parameters to be available in the servlet context.
     
  2. MyServletContextListener, which implements ServletContextListener, is configured in the deployment descriptor using the following tags:
      <listener>
          <listener-class>chapter6.MyServletContextListener</listener-class>
      </listener>
    
    It prints debug messages on the console when the context is created or destroyed. You'll see these messages when Tomcat starts or shuts down.
    Try writing your own class that implements the ServletContextListener interface and prints some messages using System.out.println() on the console. Then add that as a listener in web.xml and see the result on the console when Tomcat starts up or shuts down.