i have following three files - Head First Servlets and JSP Page Page 171, 172, 173 -
I compiled this with c:\scwcd\src\com\example>javac -d c:\scwcd\classes\ -classpath c:\scwcd\src\com\example\ Dog.java and it compiled with no errors but when I compiled the following code I received errors
I used this command to compile the above code c:\scwcd\src\com\example>javac -d c:\scwcd\classes\ -classpath c:\scwcd\src\com\example\ ListenerTester.java
and received following errors:
cannot find Symbol
Dog dog = (Dog) getServletContext().getAttribute("dog");
Can anyone please help me in solving this problem.
Presumably, getServletContext() is some class method? It looks like you're missing an object reference.
That's not the problem. getServletContext() is declared in the ServletConfig interface which is implemented by GenericServlet, the parent of HttpServlet.
Change into the project directory and try to compile using this command:
javac -classpath "<the path to servlet-api.jar>;<the path to your_project_name\classes>" -d classes src\com\example\ ListenerTester.java
It looks as if your not compiling from your project directory.
You need to include servlet-api.jar in your class path. HttpServlet is not supported in J2SE. I'm assuming that you didn't include all the compilation errors or your compiling from <tomcat_root>\lib where servlet-api.jar is located.
You need to include the path to Dog.class in your class path. That's why you got an error.
I guarantee that command will work from the project directory