| 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: 14669
|
|
|
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: 14669
|
|
|
Where did you put MyServletContextListener.class ? Under WEB-INF/classes/com/example ?
|
 |
 |
|
|
subject: Problem registering ServletContextListener
|
|
|