Iterate over Hashmap in JSP - Struts

I have a Bean class(myTO - Value Object with getters and setters) which is stored in a LinkedHashMap (called masterMap).
myTO(value object) has a Hashmap inside it.

Finally I've placed the masterMap in the request scope.

Can any one suggest me how to iterate the myTO(which is inside masterMap) , along with corresponding HashMap inside myTo (in JSP-Struts)?

I was able to go one level. i.e, iterate the myTO inside masterMap. But couldnt itterate the Hashmap insde the myTO(have to itterate using a key which is stored in a string array)

Sorry, If the Question is confusing :(
Who is Participating?
rama_krishna580Connect With a Mentor Commented:
look at here it might help you..

sounds like you need the key, otherwise how can you access the map

I have done something similar (I think).  

Let me understand exactly what you are doing...

you have a LinkedHashMap called masterMap, which holds a collection of MyTO objects.  These objects also contain a HashMap which you want to iterate over?  If that is correct you can try the following:

1) retrieve the masterMap from the request.
2) retrieve the set of keys from masterMap using masterMap.keySet();
3) iterate through the keys retrieving the myTO object.
4) for each myTO object, retrieve the HashMap.
5) again, use the keySet method of HashMap to get a Set of the keys.
6) iterate through the keys to retrieve the values/object associated.

example code:

LinkedHashMap<String, myTO> masterMap = (LinkedHashMap<String, myTo>)request.getAttribute("masterMap");

Set<String> keysForMasterMap = masterMap.keySet();
Iterator<String> keysIterator = keysForMasterMap.iterator();


String key =;
MyTO myTO = masterMap.get(key);

HashMap<String, XXXX> mapFromMyTO = myTO.getXXXX();

Set<String> keysFromMyTOMap = mapFromMyTO.keySet();
Iterator<String> myTOMapKeysIterator = keysFromMyTOMap.iterator();

String keyForObject =;
ObjectXXXX objectRetrieved = mapFromMyTO.get(keyForObject);

//Now you can do something with the object you have retrieved.


110210Author Commented:
Phoenix101- I want to do it in JSP, using <logic:..> tags and not in Java.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.