web.xml文件中:
- <listener>
  <listener-class>com.listeners.MyContextListener</listener-class> 
  </listener>
- <listener>
////////////////////////
package com.listeners;import javax.servlet.ServletContext;
import javax.servlet.ServletContextAttributeEvent;
//import javax.servlet.ServletContextAttributesListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;public final class MyContextListener
    implements ServletContextListener {  private ServletContext context = null;  public MyContextListener() {}  //This method is invoked when the Web Application
  //has been removed and is no longer able to accept
  //requests  public void contextDestroyed(ServletContextEvent event)
  {    //Output a simple message to the server's console
    System.out.println("The Simple Web App. Has Been Removed");
    this.context = null;  }
  //This method is invoked when the Web Application
  //is ready to service requests
//这样你就可以在下面的方法里面检查系统的环境了,肯定是在servlet初始
//化之前的
  public void contextInitialized(ServletContextEvent event)
  {
    this.context = event.getServletContext();    //Output a simple message to the server's console
    System.out.println("The Simple Web App. Is Ready");  }
}