Iterate over Hashmap in JSP - Struts

Posted on 2009-02-08
Last Modified: 2013-11-24

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 :(
Question by:110210
    LVL 92

    Expert Comment

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


    Expert Comment

    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.



    Author Comment

    Phoenix101- I want to do it in JSP, using <logic:..> tags and not in Java.
    LVL 23

    Accepted Solution

    look at here it might help you..


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    The viewer will learn how to implement Singleton Design Pattern in Java.
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now