File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes ServletContextListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "ServletContextListener" Watch "ServletContextListener" New topic
Author

ServletContextListener

Jaggi Kunal
Ranch Hand

Joined: Jan 21, 2003
Posts: 45
I am finding problems using the ServletContextListener. I am using Tomcat4.1.12
package com.listeners;
import javax.servlet.*;
public final class MyContextListener
implements ServletContextListener {
private ServletContext context = null;
public MyContextListener() {}
public void contextDestroyed(ServletContextEvent event)
{
System.out.println("The Simple Web App. Has Been Removed");
this.context = null;
}
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");
}
}
I have placed the MyContextListener.class file in D:\Tomcat 4.1\webapps\ROOT\WEB-INF\classes\com\listeners
Following are the changes made to the Deployment Descriptor (web.xml file located in D:\Tomcat 4.1\webapps\ROOT\WEB-INF)
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
<!-- Define application events listeners -->
<listener>
<listener-class>
com.listeners.MyContextListener
</listener-class>
</listener>
</web-app>
Now when I start the Serve, the screen is cluttered with a huge stack trace. There seems to be some problem with the <listener> tag. How can I make this code run?
Regards,
Kunal Jaggi
SCJP2
chanoch wiggers
Author
Ranch Hand

Joined: May 24, 2001
Posts: 245
might be easier to answer this if you post the stack trace


chanoch<p><a href="http://www.amazon.com/exec/obidos/ASIN/1861007736/" target="_blank" rel="nofollow">Author of Professional Apache Tomcat</a></p>
 
Don't get me started about those stupid light bulbs.
 
subject: ServletContextListener