• 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

cannot find symbol

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
location: com.example.ListenerTester
Dog dog = (Dog) getServletContext().getAttribute("dog");
...........
Can anyone please help me in solving this problem.

 
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tahir:

Presumably, getServletContext() is some class method? It looks like you're missing an object reference.

John.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can get ServletContext either useing ServletRequest object or ServletConfig.
request.getServletContext() or getServletConfig().getServletContext()
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

Hello Tahir,

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.

1.

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.

2.

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
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tahir wrote:
javac -d c:\scwcd\classes\ -classpath c:\scwcd\src\com\example\ ListenerTester.java



Your classpath is empty according to your command above. Compile from src directory and add the servlet.jar and path to other classes used in the servlet to the classpath.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there anything useful in our FAQ?
 
Tahir Abbas
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Thanks to every one for solving this problem especially to Ryan Beckett for giving a detailed reply

Tahir
 
reply
    Bookmark Topic Watch Topic
  • New Topic