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

Recommended Answers

All 3 Replies

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");

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

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? :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.