954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Session variables

I have a string stored in a session variable.....how do I get that string back out as I get the error:Type mismatch: cannot convert from Object to String

Is there a toString() method or something?

Thanks

eddy556
Light Poster
32 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

You will have to cast it to the reference type you are expecting it to return. This is because the specifications say that getAttribute() returns a variable of type Object which of course makes sense since it enables us to store a reference variable of any kind. Maybe something along the lines of:

session.setAttribute("isLoggedIn", Boolean.TRUE);
Boolean b = (Boolean)session.getAttribute("isLoggedIn");
~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

Thanks mate I was being stupid....newbie ya see? Lol I figured out by myself, thanks anyway :-)

eddy556
Light Poster
32 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

If you find a solution to a problem, it is recommended that you mark it as solved by clicking the Mark it as solved link, and if possible, posting the solution which worked for you. That way, someone else facing the problem who stumbles upon this thread might find your answer to be useful. I guess this is the least we all can do, can't we? :-)

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You