aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HFS page 171 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HFS page 171" Watch "HFS page 171" New topic
Author

HFS page 171

pallavi utukuri
Ranch Hand

Joined: Feb 10, 2004
Posts: 182
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());
}
}


Thanks,<br />Pallavi
vishwa venkat
Ranch Hand

Joined: Nov 22, 2003
Posts: 185
Try setting classpath..
Bryan Basham
author
Ranch Hand

Joined: Apr 30, 2001
Posts: 199
deleted
[ September 20, 2004: Message edited by: Bryan Basham ]
Jayanthi Mani
Greenhorn

Joined: Dec 08, 2000
Posts: 25
So,what was the answer to this problem - I am also getting the same error....

Jayanthi.
Jayanthi Mani
Greenhorn

Joined: Dec 08, 2000
Posts: 25
Thanks,Pallavi- this also worked for me:

javac MyServletContextListener.java Dog.java
pallavi utukuri
Ranch Hand

Joined: Feb 10, 2004
Posts: 182
set classpath=%classpath%;D:\Tomcat4.1\webapps\listenertest\web-inf\classes\com\example

javac Dog.java
javac ListenerTester.java
javac MyServletContextListener.java
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HFS page 171