• 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

HFS page 171

 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
created Dog.java as follows

package com.example;
public class Dog{
private String breed;

public Dog(String breed){
this.breed=breed;
}
public Dog(){}
public String getBreed(){
return breed;
}
}

compiled it using
javac -classpath /tomcat4.1/common/lib/servlet-api.jar:classes:.; C:\j2sdk1.4.2_05\lib\j2ee.jar; -d classes src/com/example/Dog.java
it compiled

But MyServletContextListener and ListenerTester when compiled showed the errors cannot resolve symbol class Dog .....what is thw silly mistake i am doing here

package com.example;
import javax.servlet.*;

public class MyServletContextListener implements ServletContextListener{

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){

}
}


package com.example;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class ListenerTester extends HttpServlet{

public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException {
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("test context attribute set by listenst<br>");
Dog dog=(Dog) getServletContext().getAttribute("dog");
out.println("Dog's breed:"+dog.getBreed());
}
}
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try setting classpath..
 
author
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
deleted
[ September 20, 2004: Message edited by: Bryan Basham ]
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So,what was the answer to this problem - I am also getting the same error....

Jayanthi.
 
Jayanthi Mani
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks,Pallavi- this also worked for me:

javac MyServletContextListener.java Dog.java
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
set classpath=%classpath%;D:\Tomcat4.1\webapps\listenertest\web-inf\classes\com\example

javac Dog.java
javac ListenerTester.java
javac MyServletContextListener.java
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic