Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Values of HttpSession object

 
PradeepPillai Pradeep
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getValue is deprecated and replaced with getAttribute.

With setAttribute, you can retrieve whatever values you put into it using setAttribute.
 
Jaime M. Tovar
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
PradeepPillai Pradeep
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic