IntelliJ Java IDE
The moose likes JSP and the fly likes about session Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "about session" Watch "about session" New topic
Author

about session

Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1291

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,


Saifuddin..
[Linkedin] How To Ask Questions On JavaRanch My OpenSource
Natasza Biecek
Greenhorn

Joined: Oct 26, 2006
Posts: 28
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

Joined: Nov 16, 2005
Posts: 502

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.


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
 
 
subject: about session
 
Threads others viewed
problem with sessions - urgent please
Delete/update associations question
global-forwards
Session is not working
session setAttribute null not working
MyEclipse, The Clear Choice