| Author |
iterate HashMap<String,List> 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: 56202
|
|
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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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: 56202
|
|
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: 56202
|
|
|
What problems are you seeing when you use that code?
|
 |
Prasad Krishnegowda
Ranch Hand
Joined: Apr 25, 2010
Posts: 503
|
|
|
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.
|
Regards, Prasad
SCJP 5 (93%)
|
 |
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
|
 |
 |
|
|
subject: iterate HashMap<String,List> in My jsp page
|
|
|