aspose file tools*
The moose likes JSP and the fly likes  iterate HashMap<String,List> in My jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark " iterate HashMap&lt;String,List&gt; in My jsp page" Watch " iterate HashMap&lt;String,List&gt; in My jsp page" New topic
Author

iterate HashMap&lt;String,List&gt; in My jsp page

Niharika Sweety
Greenhorn

Joined: Feb 11, 2012
Posts: 6
Hi Friends ..Please help- me
I want to iterate HashMap<String,List> in My jsp page..

My requirement is like this

ID Locations
123 Abc,def,ghi, etc.
456 Kjl,mno etc..

here i got values from DB and I was set in HashMap like this HashMap<id,location> now i want display these values in to my Jsp..

Thanks..... please help me.. urgent
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

Assuming that you have placed the Map into a scoped variable -- let's call it myMap -- you can iterate over the Map.Entry values of the Map with the JSTL forEach tag as follows:

Within the body of the tag, the variable entry will represent each Map.Entry in turn. You can get the key with ${entry.key} and the value (which in this case is your List) with ${entry.value}.

If you need to iterate over the List, you'd use another forEach tag to iterate over it.

With that, give writing your code a try. We'll help you with any problems you have along the way.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Niharika Sweety
Greenhorn

Joined: Feb 11, 2012
Posts: 6
Thanks for replay...
ACtually i'm getting HashMap values from applicationBean.getRacfLoc(); this method..

my code is like this ..



Please translate this code with JSP syntaxes.. I have to display in jsp page only...
Thanks..


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

No, I will not write the code for you. And no, you should not be doing this with Java code in a JSP. That's a bad practice that's been discredited for over 10 years now.

You should be using the JSTL and EL in JSP pages, and the <c:forEach> JSTL tag as I described is the best way to achieve your goals.
Niharika Sweety
Greenhorn

Joined: Feb 11, 2012
Posts: 6


Thanks Please provide me JSTL code for

HashMap<String,List<String>> iteration..

I'm written here.. Please correct me if any mistake, because of i dn't know JSTL..


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

What problems are you seeing when you use that code?
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 560
    
    3

The code you have written is fine. But, why can't you place the hashMap in scoped variable, instead of using scriplets to assign its value to JSTL variable? I would recommend not to use even a single line of scriplets in JSP.
Niharika Sweety
Greenhorn

Joined: Feb 11, 2012
Posts: 6
Thanks i'm resolved my problem.. with this code
Thanks a lot for you are help


 
jQuery in Action, 2nd edition
 
subject: iterate HashMap&lt;String,List&gt; in My jsp page