This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JSTL for loop error

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: <c:out 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.
 
Marshal
Posts: 25669
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's a "Comments" object and what makes you think it's possible to iterate over such an object?
 
agustinus lumbantoruan
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Marshal
Posts: 25669
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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" >

    Bookmark Topic Watch Topic
  • New Topic