• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem registering ServletContextListener

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post MyServletContextListener.java, and also the way you registered it in web.xml.
 
raghu dubey
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where did you put MyServletContextListener.class ? Under WEB-INF/classes/com/example ?
reply
    Bookmark Topic Watch Topic
  • New Topic