• 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

JSTL printing issue

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have this problem..

In a JAVA class I have the below code


In a JSP, I have written a JSTL which is written this way,


So basically what I have is, a Hashmap which has String as a key and an ArrayList object as a value.
When I try to run this, I get the error cannot run forEach for "items".
What part of code am I not writing correctly? Please help.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai
culprit:
request.setAttribute("param",map);

change your name from param to param1 or something else..because param is one of the implicit object in EL...more over for:Each items should be collection or array

Hope THis Helps
 
Sripathi Krishnamurthy
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by seetharaman venkatasamy:
hai
culprit:
request.setAttribute("param",map);

change your name from param to param1 or something else..because param is one of the implicit object in EL...more over for:Each items should be collection or array

Hope THis Helps



The one I have given above is just an example. I havent used param as I have given there. The variable names that I am using in my application is entirely different. For this example, you can assume it as "param1" as you have indicated.
Thanks
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
insteadof <c:out value="${users}"/> you just use

${uesrs}...and let me know
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you iterate over a map you are iterating over the entry set, not the map directly. This means that each value returned by the outer loop is a MapEntry, not an ArrayList. The MapEntry would have a method getValue() which would return the ArrayList to use for the inner loop. Example:
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks luke
 
Sripathi Krishnamurthy
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Steve Luke:
When you iterate over a map you are iterating over the entry set, not the map directly. This means that each value returned by the outer loop is a MapEntry, not an ArrayList. The MapEntry would have a method getValue() which would return the ArrayList to use for the inner loop. Example:



Thank you very much. It is working fine now.
Regards
 
I don't like that guy. The tiny ad agrees with me.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic