aspose file tools*
The moose likes JSP and the fly likes JSTL for loop error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL for loop error" Watch "JSTL for loop error" New topic
Author

JSTL for loop error

agustinus lumbantoruan
Ranch Hand

Joined: Jul 17, 2010
Posts: 56
In this topic, I would like to ask what is going on with this problem and how could I solved this problem?

Yes...Below is the snippet of the error I've got.

org.apache.jasper.JasperException: An exception occurred processing JSP page /Profile/profile.jsp at line 41

38: <fieldset class="frame">
39: <div class="whitepaper">
40: <blockquote>
41: <c:forEach items="${myProfileComments}" var="comments">
42: <cut value="${co.arraylistComments}"/>
43: </c:forEach>
44: </blockquote></div></fieldset></div>

root cause

javax.servlet.ServletException: javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in <forEach>
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.Profile.profile_jsp._jspService(profile_jsp.java:138)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

root cause

javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in <forEach>
org.apache.taglibs.standard.tag.common.core.ForEachSupport.toForEachIterator(ForEachSupport.java:255)
org.apache.taglibs.standard.tag.common.core.ForEachSupport.supportedTypeForEachIterator(ForEachSupport.java:219)
org.apache.taglibs.standard.tag.common.core.ForEachSupport.prepare(ForEachSupport.java:137)
javax.servlet.jsp.jstl.core.LoopTagSupport.doStartTag(Unknown Source)
org.apache.jsp.Profile.profile_jsp._jspx_meth_c_005fforEach_005f0(profile_jsp.java:211)
org.apache.jsp.Profile.profile_jsp._jspService(profile_jsp.java:123)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)


Now let us see what happens before the error came out of it's cave

Let see the servlet code


Last but not least, I would like to itterate myProfikeComments in the JSP code below.
Unfortunately it gives me a 500 error.



Would some one kindly enough to help me out here please. I have spent tenths of hours on solving this problem. I really appreciate your time.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

What's a "Comments" object and what makes you think it's possible to iterate over such an object?
agustinus lumbantoruan
Ranch Hand

Joined: Jul 17, 2010
Posts: 56
Paul Clapham wrote:What's a "Comments" object and what makes you think it's possible to iterate over such an object?


Thanks for the response man.

the comments is a variable of JSTL.

Btw code update. It works but it does not give me what I wanted



The code above displays all of the array value 3X instead of displaying each element.
The image below show you what I mean with what is going on


I am trying to achieve something like this


1
Comment:Biobiobiobiobio
Written by: Bio
________________________________

2
Comment: Dear Agustinus. Nice video man!
Written by:Agustinus
________________________________

3
Comment: Test123 123
Written by:Agustinus


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

The images tell me nothing. We're talking about JSTL here. JSTL has rules about what you can iterate over; you
could (and should) read the JSTL specs to find out what those rules are. Then review the Comments class (the one
which I asked you about but you didn't reply). We already know from the error message that a Comments object
isn't one of the things which JSTL can iterate over. But perhaps it has a method which returns some kind of a list of
comments, or something else which JSTL can iterate over.
agustinus lumbantoruan
Ranch Hand

Joined: Jul 17, 2010
Posts: 56
Paul Clapham wrote:The images tell me nothing. We're talking about JSTL here. JSTL has rules about what you can iterate over; you
could (and should) read the JSTL specs to find out what those rules are. Then review the Comments class (the one
which I asked you about but you didn't reply). We already know from the error message that a Comments object
isn't one of the things which JSTL can iterate over. But perhaps it has a method which returns some kind of a list of
comments, or something else which JSTL can iterate over.


The Comments is a variable or instance of the class below
The code below retrieves comments and it's formation from the database.
The servlet will access this code and set it into a session.setAttribute("myProfileComments", myProfileComments);, then pass that attribute into the JSP page.
The JSP page will loop the arraylist.....<c:forEach myProfileComments.arraylistComments}" var="comments" >

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSTL for loop error