• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL question: retrieving a hashmap from session

 
seena mathew
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a hashmap which is stored in a session. The hashMap is a map of maps.

I dont want to use scriptlets. But I am stuck with one scriptlet and cant seem to make it work. Any suggestions where I am going wrong would be great.
The following combination of SCRIPTLET + JSTL works
Scriptlet:

JSTL code:

Now if I try to replace scriptlet code with following( with no change in JSTL code)

I get the following error
 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't nest custom tags as attributes to other custom tags.
And in this case you don't want to. The <c:out tag> converts it to a String. Which is definitely NOT what you want.

You could do either
<c:set var="mapofMaps" value ='${HashMapStoredInSession}'/>
or
<c:set var="mapofMaps" value ='${sessionScope.HashMapStoredInSession}'/>


or you could just directly use ${sessionScope.HashMapStoredInSession} in your forEach loop.

 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Taking another look at the code, you loop through the inner map, and then do if checks for specific properties.
If you know what the properties you want out of the map are, then you don't need the inner loop - you can just retrieve them directly from the map.
I believe this is what the code could be simplified to:



 
seena mathew
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stefan for your valuable suggestions!!! I removed the looping from the code and retrived the values directly from the hash map.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!