This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Servlets and the fly likes Values of HttpSession object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Values of HttpSession object" Watch "Values of HttpSession object" New topic
Author

Values of HttpSession object

PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
How can I get the values of an HttpSession Object. From the API, I know that I can use getValue method.
But how would I know what are the values I can get?
Any help greately appreciated.
Thanks in advance,
Pradeep
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

getValue is deprecated and replaced with getAttribute.

With setAttribute, you can retrieve whatever values you put into it using setAttribute.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jaime M. Tovar
Ranch Hand

Joined: Mar 28, 2005
Posts: 133
If you are looking for the names you can do a getAttributeNames() this will return an enumeration with all the names of attributes in session then you can iterate the enumeration to get each and then ask for its value with getAttribute(name)


She will remember your heart when men are fairy tales in books written by rabbits.<br /> As long as there is duct tape... there is also hope.
PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
Thank you. Both of the replies are helpful. Hi Bear, so in order to get values or attributes do I have to set attributes first?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

Objects that you set into the session using setAttribute are known as scoped variables. You can also set such variables into page (if a JSP), request, and application scopes.

For the session, I do not believe that there are any built-in values. So if you don't put anything there, there's nothing to retrieve.

The container will sometimes populate the other scopes with some built-in values (for example, putting error information into request scoped variables when an error is detected).
PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
Thank you
 
GeeCON Prague 2014
 
subject: Values of HttpSession object