This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

iterate HashMap<String,List> in My jsp page

 
Niharika Sweety
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64189
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Niharika Sweety
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64189
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Pie
Posts: 64189
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What problems are you seeing when you use that code?
 
Prasad Krishnegowda
Ranch Hand
Posts: 665
4
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks i'm resolved my problem.. with this code
Thanks a lot for you are help


 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic