KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > javax > servlet > ServletContextEvent

javax.servlet
Class ServletContextEvent

java.lang.Object
  extended byjava.util.EventObject
      extended byjavax.servlet.ServletContextEvent
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ServletContextAttributeEvent
See Also:
Top Examples, Source Code, ServletContextListener

public ServletContext getServletContext()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[253]Implement ServletContextListener
By Anonymous on 2005/03/21 04:58:10  Rate
public final class ContextListener 
     implements ServletContextListener  {  
     private ServletContext context = null; 
      
     public void contextInitialized ( ServletContextEvent event )   {  
     context = event.getServletContext (  ) ; 
     try  {  
         BookDB bookDB = new BookDB (  ) ; 
         context.setAttribute ( "bookDB", bookDB ) ; 
      }  catch  ( Exception ex )   {  
         context.log ( "Couldn't create bookstore 
         database bean: " + ex.getMessage (  )  ) ; 
      }  
      
     Counter counter = new Counter (  ) ; 
     context.setAttribute ( "hitCounter", counter ) ; 
     counter = new Counter (  ) ; 
     context.setAttribute ( "orderCounter", counter ) ; 
      }  
      
     public void contextDestroyed ( ServletContextEvent event )   {  
         context = event.getServletContext (  ) ; 
         BookDB bookDB =  ( BookDB ) context.getAttribute ( "bookDB" ) ; 
         bookDB.remove (  ) ; 
         context.removeAttribute ( "bookDB" ) ; 
         context.removeAttribute ( "hitCounter" ) ; 
         context.removeAttribute ( "orderCounter" ) ; 
      }  
  } 


public ServletContextEvent(ServletContext source)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags