• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServletContextListener

 
Ravinder S Edhan
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic