Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to store map value in session  RSS feed

 
vijayakumar durai
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anybody tell how to store map value in session ?and how to retrieve the value map value from session? can any body give sample example
 
Vijitha Kumara
Saloon Keeper
Posts: 3997
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to store map value in session ?


Did you mean how to set an attribute (which contained in a map) in a session? or you are talking about sessionScope implicit object availabe in EL?
 
vijayakumar durai
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want set the map value in session and want to retrive the map value in session
 
Vijitha Kumara
Saloon Keeper
Posts: 3997
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't you use



and to retrieve



?
[ November 18, 2008: Message edited by: Vijitha Kumara ]
 
vijayakumar durai
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i will set in session .it will set both key and value ? how can i only set the value in session
and how can iterate the value?
 
Vijay Jeyam
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To Store in session
Map someMap = new HashMap();
// Do some processing to populate map
request.getSession().setAttribute("nameoftheObject",someMap);


:
:
:

To get values

Map someMap = (Map)request.getSession().getAttribute("nameoftheObject");

/// Put what you need or Iterate....
 
Vijitha Kumara
Saloon Keeper
Posts: 3997
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want to set only one value? or a set of key/value which may be a map object? setAttribute() method accept any object so you will have no problem with both cases as long as former can be represent as an object.
[ November 18, 2008: Message edited by: Vijitha Kumara ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!