File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes getServletContext() error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "getServletContext() error" Watch "getServletContext() error" New topic

getServletContext() error

Damodara Reddy
Ranch Hand

Joined: Feb 09, 2007
Posts: 44

While compiling my application I am getting the error saying " can not resolve symbol getServletContext() in HttpSession.
I have set the classpath to servlet-api.jar and servlet.jar

Please help me in resolving the above problem.

Thanks & Regards
Damodar Reddy G

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

There is a getServletContext method in HttpSession.

If the compiler found HttpSession then it's probably not a classpath issue.
Check your spelling.

You didn't, by any chance, name one of your objects HttpSession, did you?

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Joan Horta Tosas
Ranch Hand

Joined: Feb 01, 2007
Posts: 59
As it says in the API doc, this method appeared in Servlet API 2.3, which is covered on J2EE 1.3. Are you using an updated servlet-api.jar and servlet.jar (for example, from Tomcat 4.1 or 5.x or 6.x)? If you're developing using an IDE, look for the target J2EE, maybe it's configured by default to 1.2 or 1.1...
Damodara Reddy
Ranch Hand

Joined: Feb 09, 2007
Posts: 44
I have tried with the updated version(servlet-api.jar) also, still I am getting the same error.
Abdul Kader
Ranch Hand

Joined: Apr 11, 2007
Posts: 115
are you using IDE for this code development
I agree. Here's the link:
subject: getServletContext() error
jQuery in Action, 3rd edition