• 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

ServletContextListener

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I'm try'n to write a listner class.
*************************************************
package com.example;

import javax.servlet.*;

public class MyServletContextListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
ServletContext ctx = event.getServletContext();
String refDog = ctx.getInitParameter("breed");

Dog d = new Dog(refDog);

ctx.setAttribute("dog",d);
}
public void contextDestroyed(ServletContextEvent event) {
//No implemantation required yet.
}
}
***********************************
The above is an example from Head First Servlet and JSP.

While compiling the file I'm getting following error

Compiling command:
javac -d web-inf/classes src/*.java

Error:

src/MyServletContextListener.java:5: cannot resolve symbol
symbol : class ServletContextListener
location: class com.example.MyServletContextListener
public class MyServletContextListener implements ServletContextListener {
^
src/MyServletContextListener.java:6: cannot resolve symbol
symbol : class ServletContextEvent
location: class com.example.MyServletContextListener
public void contextInitialized(ServletContextEvent event) {
^
src/MyServletContextListener.java:19: cannot resolve symbol
symbol : class ServletContextEvent
location: class com.example.MyServletContextListener
public void contextDestroyed(ServletContextEvent event) {
^
3 errors

The carrot sign are coming under ServletContextListener, ServletContextEvent

I don't know why.
Thanks in advance

Ravinder S Edhan
[ January 11, 2005: Message edited by: Ravinder S Edhan ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have the servlet libs on your CLASSPATH?

For recent versions ofTomcat, they're in TOMCAT_HOME/common/lib/servlet-api.jar

Your container's mileage may vary.
[ January 11, 2005: Message edited by: Ben Souther ]
 
Ravinder S Edhan
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben

Thanks for the reply. After specifying the CLASSPATH for 'servlet-api.jar' the files compiled.

Cheers
Ravinder S Edhan
 
reply
    Bookmark Topic Watch Topic
  • New Topic