File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes cannot find symbol : ServletContextListner Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "cannot find symbol : ServletContextListner" Watch "cannot find symbol : ServletContextListner" New topic
Author

cannot find symbol : ServletContextListner

Deepti Arora
Greenhorn

Joined: Oct 10, 2010
Posts: 6
Hi,

I am trying to do the ListnerTester example from Head First Servlet & Jsp Book (chapter 5 ).
It has 3 classes
1. Dog (Plain old java code)
2. ListnerTester (A servlet that test the listner class)
3. MyServletContextListner ( A listner that implements ServletContextListner)

I am able to compile Dog & ListnerTester but when i try to compile MyServletContextListner it gives en error cannot find symbol
symbol : class ServletContextListner

The code of MyServletContextListner is as follows

package com.example;

import javax.servlet.*;

public class MyServletContextListner implements ServletContextListner{

public void contextInitialized(ServletContextEvent event){
ServletContext sc=event.getServletContext();
String dogBreed=sc.getInitParameter("breed");
Dog d=new Dog(dogBreed);
sc.setAttribute("dog",d);
}

public void contextDestroyed(ServletContextEvent event){
}

}



Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Welcome to JavaRanch!
Did you have javax.servlet.* package? How do you suppose run this code?


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Deepti Arora
Greenhorn

Joined: Oct 10, 2010
Posts: 6
I am able to compile ListnerTester which also imports javax.servlet

It has the following code

package com.example;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class ListnerTester extends HttpServlet{

public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException{
response.setContentType("text/html");
PrintWriter out=response.getWriter();

out.println("Test context Attributes set by Listner<br>");
out.println("<br>");

Dog dog=(Dog) getServletContext().getAttribute("dog");

out.println("Dog's Breed is "+ dog.getBreed());


}
}
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Please => UseCodeTags when post code snaps. Use Edit button and insert code tags. It'll be more readable!
For, running a servlet/jsp application, you need a web container like tomcat. Do you have/install it?
Deepti Arora
Greenhorn

Joined: Oct 10, 2010
Posts: 6
yes i have installed tomcat

i am trying to compile it from command prompt using the following command.

D:\MyProjects\listnerTest>javac -classpath c:\tomcat\common\lib\servlet-api.jar;
classes; -d classes src\com\example\MyServletContextListner.java
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8



The error message means exactly what it says. Why don't you check to see if you spelled the name of the interface correctly?
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

@deepti..try to put exactly the same copy of error which you got on commond prompt.


SCJP6.0,My blog Ranchers from Delhi
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

Paul has already identified the problem.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Deepti Arora
Greenhorn

Joined: Oct 10, 2010
Posts: 6
I think the name of the interface is correct.i am attaching the print screen of the command prompt.



[Thumbnail for error.jpg]

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Deepti Arora wrote:I think the name of the interface is correct.

It isn't.
i am attaching the print screen of the command prompt.

Which tells you that it is not correct.
Deepti Arora
Greenhorn

Joined: Oct 10, 2010
Posts: 6
i did not get it...am i implementing the wrong interface?
if yes then instead of ServletContextListner which interface should i implement?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

Deepti Arora wrote:i did not get it...am i implementing the wrong interface?
if yes then instead of ServletContextListner which interface should i implement?

The one without the spelling mistakes.
Deepti Arora
Greenhorn

Joined: Oct 10, 2010
Posts: 6
oopss... a silly mistake...
Thanks i am able to compile it now...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot find symbol : ServletContextListner