This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

about session  RSS feed

 
Muhammad Saifuddin
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

I use this code to retieve the value from session in my jsp



but it didn't work but after applying this



it works fine..

My Question is.

Why my first code was not working ?
What session.getAttribute() return ?

Thanks,
 
Natasza Biecek
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getAttribute() of HttpSession returns object (java.lang.Object)
http://java.sun.com/j2ee/sdk_1.2.1/techdocs/api/javax/servlet/http/HttpSession.html

so, it has to be casted to string, if not - expect error like this:
"Type mismatch: cannot convert from Object to String."

regards,
Natasza
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you get any attributes in (request,session, application)using getAttribute() will return of type Object. So, you need to type cast it back to the Original class it belongs.

What session.getAttribute() return ?


Please refer API Reference documentation for these type of questions.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!