This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Tomcat and the fly likes contextDestroyed- odd behaviour? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "contextDestroyed- odd behaviour?" Watch "contextDestroyed- odd behaviour?" New topic

contextDestroyed- odd behaviour?

John Jones

Joined: Feb 17, 2005
Posts: 1
I have a very simple class that implements ServletContextListener.
When Tomcat is shut down, contextDestroyed is run, but the context variables are already null when I try to access them. Is this the appropriate behaviour? I would have thought they would not destroyed until after contextDestroyed finishes running.
I wrote a simple jsp page as well to make sure that I could access the variable before shutdown.
I am running Tomcat 5.5.7 on Windows 2000.

Here is my code:

Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
Did you configure your implementation class in the deployment descriptor of your web application?

And the "test" JSP page is included in the same web application?
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
This sounds more like a JSP/Servlet issue than a Apache/Tomcat?
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

I just tested your code in TC5.28 and it seems to be working fine.
Here is the output to catalina.out, generated when reloading the app from the html manager in Tomcat:

==> catalina.out <==
- Reloading this Context has started
test = This is a test

I've bundled the test into a war file:
Try with this war file.

If I get a chance later, I'll try in 5.5.7

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
It is sorta covered in the JavaRanch Style Guide.
subject: contextDestroyed- odd behaviour?
Similar Threads
When HttpSessionAttributeListener and HttpSessionBindingListener methods are called?
Servlet filter question
context variable in action servlet
A small chicken and the egg situation!
Cannot get HttpSessionBindingListener method valueBound to trigger