• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

iterate HashMap<String,List> in My jsp page

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What problems are you seeing when you use that code?
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks i'm resolved my problem.. with this code
Thanks a lot for you are help


reply
    Bookmark Topic Watch Topic
  • New Topic