File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes JSTL printing issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL printing issue" Watch "JSTL printing issue" New topic
Author

JSTL printing issue

Sripathi Krishnamurthy
Ranch Hand

Joined: Mar 07, 2005
Posts: 232
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.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Mar 07, 2005
Posts: 232
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

Joined: Jan 28, 2008
Posts: 5575

insteadof <cut value="${users}"/> you just use

${uesrs}...and let me know
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4164
    
  21

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:


Steve
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Thanks luke
Sripathi Krishnamurthy
Ranch Hand

Joined: Mar 07, 2005
Posts: 232
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JSTL printing issue
 
Similar Threads
Iterating through local List using JSTL
Jstl foreach iterate over arraylist containing map object using paramvalues
Scriptlet vs JSTL
Iterating List of Maps through c:foreach
key from HashMap