• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

guestbook, looping, beans and JSTL

 
agustinus lumbantoruan
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, sorry about the title. I do not know the proper title for this problem

Good day Java Programmers.

Feels good to be here =)

So straight to the topic.

I have been coding these codes below, but it gives me this message.....

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

43:
44: <c:forEach var="i" begin="0" end="${mb.arrayListSize}" varStatus ="comment">
45: <jsp:setProperty name="mb" property="x" value="${i}" />
46: ${mb.comments}<br>
47: ${mb.x}<br>
48: </c:forEach>
49: </blockquote></div></fieldset></div>


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
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.el.ELException: Error reading 'comments' on type malo.classes.database.Comments
javax.el.BeanELResolver.getValue(BeanELResolver.java:66)
javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
org.apache.el.parser.AstValue.getValue(AstValue.java:118)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:935)
org.apache.jsp.Profile.profile_jsp._jspx_meth_c_005fforEach_005f0(profile_jsp.java:235)
org.apache.jsp.Profile.profile_jsp._jspService(profile_jsp.java:134)
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

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
java.util.ArrayList.RangeCheck(ArrayList.java:547)
java.util.ArrayList.get(ArrayList.java:322)
malo.classes.database.Comments.getComments(Comments.java:174)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
org.apache.el.parser.AstValue.getValue(AstValue.java:118)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:935)
org.apache.jsp.Profile.profile_jsp._jspx_meth_c_005fforEach_005f0(profile_jsp.java:235)
org.apache.jsp.Profile.profile_jsp._jspService(profile_jsp.java:134)
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)


The code I made in the JSP is something simple like this

The JSP creates a bean ID= mb.

Then I tried to loop. begin=0 end="${mb.arrayListSize}"the size of the array list.

Inside the loop I called a get method name comments. I used EL to achieve that...${mb.comments}

${mb.x} This is used to display the integer of x.

The java bean code is something like this below. So the java bean code contains Setter and Getters methods.



I hope I have given enough detail about the problem. I could give you a little more detail if you do not understand the problem.
Care anyone to help me solve the problem please.
Thank you and God Bless
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you have an empty list. If you're trying to loop through an entire list, there is no need for the "begin" and "end" attributes; supplying them will force direct access to a specific index, and failure when the list is empty.
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your arrayListComments empty?? There is an exception at the statement
which means that there was no element at the first index in your ArrayList which means it must be empty. You've not shown us the full code of your Comments class (so we don't know if you fill arrayListComments in the constructor) and we don't know if there is already a bean named mb in page scope which has a non-empty arrayListComments...
 
agustinus lumbantoruan
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Garg wrote:Is your arrayListComments empty?? There is an exception at the statement
which means that there was no element at the first index in your ArrayList which means it must be empty. You've not shown us the full code of your Comments class (so we don't know if you fill arrayListComments in the constructor) and we don't know if there is already a bean named mb in page scope which has a non-empty arrayListComments...


Thanks guys for the response and sorry I respond late because I usually do JSP SERVLET every weekend.

This is strange, the code is already worked with JSP Script <%= /%> without the JSTL.

Update code



The JSP Code

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
agustinus lumbantoruan wrote:First of all, sorry about the title. I do not know the proper title for this problem

Please avoid all caps and excessive punctuation in titles, thanks.
 
agustinus lumbantoruan
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
agustinus lumbantoruan wrote:First of all, sorry about the title. I do not know the proper title for this problem

Please avoid all caps and excessive punctuation in titles, thanks.


Yes Sir Sheriff Bibeault. Point taken
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic