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

Session related error

Nelo Angelo
Ranch Hand

Joined: Jul 25, 2011
Posts: 44


I am not able to create session for my Servlet. I was initially trying to session the captcha code but found continuous errors with "setAttribute". So I tried a very simple program but still the same error pops ups. Please help.

With the above code I get the following error:

cannot find symbol
symbol: method setAttribute(java.lang.String,java.lang.String)
location: interface javax.servlet.http.HttpSession

I love java but she hates me... :'(
J. Kevin Robbins

Joined: Dec 16, 2010
Posts: 1522

You have a misspelling in line 2.

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Line 2 should be import javax.servlet.http.*; I am surprised you did not get a syntax error.

So much trouble in the world -- Bob Marley
Nelo Angelo
Ranch Hand

Joined: Jul 25, 2011
Posts: 44

Thanks for the replies, but that's not the problem. I didn't copy paste the code here and its just a typo here. The package name has been written correctly in the code and the same error keeps on showing. I also checked the servlet-api.jar for classes and it contains all that are required. Have checked the environment variables for classpath issues, none found.

Is it possible that my compiler is not functioning correctly? Any suggestions?
Nelo Angelo
Ranch Hand

Joined: Jul 25, 2011
Posts: 44

I hope that everything in the doPost() body is correct.

The compiler specially points out to the setAttribute() method.

Also, if I remove "true" in HttpSession session=request.getSession(true); I get an error something like this:

getSession(boolean) in javax.servlet.http.HttpServletRequest cannot be applied to ().
Rob Spoor

Joined: Oct 27, 2005
Posts: 20276

Where did you get that servlet-api.jar file from? Because if that's correctly part of the class path, it's got wrong versions of classes / interfaces in them if it can't find these methods.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Session related error
It's not a secret anymore!