This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Servlets and the fly likes about ServletContextListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "about ServletContextListener" Watch "about ServletContextListener" New topic

about ServletContextListener

Raj Ohadi
Ranch Hand

Joined: Jun 30, 2006
Posts: 316
we have contextDestroyed contextInitialized in ServletContextListener. Now questions are --

a) when server is restarted, contextInitialized will be called; when server is shut down, contextDestroyed is called, right ?
b) when web application is redeployed, both contextDestroyed and contextInitialized will be called, right ? (old one is destroyed and new one is initiated)
c) wehn web app is undeployed, contextDestroyed is called, right ?

any other scenario that may cause either one to be called ?

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

It sounds like you've got it.

A very easy way to test your assumptions would be to put a System.out.println statement in both of your methods and watch your logs as you start, stop, and restart your application.

If you're lucky enough to be working on a Unix box, tail -f <filename> will allow you to follow your log file as you are hitting your app. If you're on Windows some text editors (Textpad is one) have settings to automatically refresh the window if the file is updated.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Consider Paul's rocket mass heater.
subject: about ServletContextListener