wood burning stoves 2.0
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Problem registering ServletContextListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Problem registering ServletContextListener" Watch "Problem registering ServletContextListener" New topic

Problem registering ServletContextListener

raghu dubey
Ranch Hand

Joined: Jul 05, 2007
Posts: 72

I am trying to run the HFSJ example on pg 170...for the ContextListener topic. I get an nullpointer when I use the URL. Here are the lines I found in tomcat logs:

SEVERE: Error configuring application listener of class com.example.MyServletContextListener
java.lang.ClassNotFoundException: com.example.MyServletContextListener
at org.apache.catalina.loader.WebappClassLoader.loadClass

SEVERE: Servlet.service() for servlet ListenerTester threw exception
at com.example.ListenerTester.doGet(ListenerTester.java:16)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
I checked the listener name in DD, but is is fine. All the classes alos compile good. Can you please help on whats goingt wrong...using tomcat 5.5.25.

Thanks,<br />Raghu.<br /> <br />SCJP 5, SCWCD 1.4, NCFM
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

Please post MyServletContextListener.java, and also the way you registered it in web.xml.

[My Blog]
All roads lead to JavaRanch
raghu dubey
Ranch Hand

Joined: Jul 05, 2007
Posts: 72
Hi Chris,

Here is the Web.xml:




<param-value>Great Dane</param-value>



package com.example;

import javax.servlet.*;

public class MyServletContextListener implements ServletContextListener{

public void contextInitialized(ServletContextEvent sce){

ServletContext sc = sce.getServletContext();
String dogBreed = sc.getInitParameter("breed");
Dog d = new Dog(dogBreed);


public void contextDestroyed(ServletContextEvent sce){


Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

Where did you put MyServletContextListener.class ? Under WEB-INF/classes/com/example ?
subject: Problem registering ServletContextListener
It's not a secret anymore!