wood burning stoves*
The moose likes Servlets and the fly likes 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 » Java » Servlets
Bookmark "ServletContextListener" Watch "ServletContextListener" New topic
Author

ServletContextListener

Ravinder S Edhan
Ranch Hand

Joined: Dec 15, 2003
Posts: 57
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

Joined: Dec 11, 2004
Posts: 13410

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 ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ravinder S Edhan
Ranch Hand

Joined: Dec 15, 2003
Posts: 57
Hi Ben

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

Cheers
Ravinder S Edhan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ServletContextListener
 
Similar Threads
Symbol not found
javac compiling problem
Package Problem
Head First Servlets and JSp problem
Hi, package compiling question...