wood burning stoves*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Problem registering ServletContextListener" Watch "Problem registering ServletContextListener" New topic
Author

Problem registering ServletContextListener

raghu dubey
Ranch Hand

Joined: Jul 05, 2007
Posts: 72
Hi,

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
java.lang.NullPointerException
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é
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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:

=======
<servlet>
<servlet-name>ListenerTester</servlet-name>
<servlet-class>com.example.ListenerTester</servlet-class>

<init-param>
<param-name>adminEmail</param-name>
<param-value>meraghudy@gmail.com</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>ListenerTester</servlet-name>
<url-pattern>/ListenTest.do</url-pattern>
</servlet-mapping>

<context-param>
<param-name>breed</param-name>
<param-value>Great Dane</param-value>
</context-param>

<listener>
<listener-class>
com.example.MyServletContextListener
</listener-class>

</listener>
=====================

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);
System.out.println(d);
sc.setAttribute("dog",d);

}

public void contextDestroyed(ServletContextEvent sce){

}

}
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Where did you put MyServletContextListener.class ? Under WEB-INF/classes/com/example ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem registering ServletContextListener
 
Similar Threads
Servlet connection with Jdbc
Tiles 2 - Tomcat Errors etc
exceptions occurring here
ClassDefNotFound on loading listener (Heads Up Servlets & JSP)
Error reading tld listeners exception with Spring's ContextLoaderListener