wood burning stoves 2.0*
The moose likes JSP and the fly likes guestbook, looping, beans and JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "guestbook, looping, beans and JSTL" Watch "guestbook, looping, beans and JSTL" New topic
Author

guestbook, looping, beans and JSTL

agustinus lumbantoruan
Ranch Hand

Joined: Jul 17, 2010
Posts: 56
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Aug 03, 2008
Posts: 9313
    
  17

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


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
agustinus lumbantoruan
Ranch Hand

Joined: Jul 17, 2010
Posts: 56
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

Joined: Jan 10, 2002
Posts: 61654
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
agustinus lumbantoruan
Ranch Hand

Joined: Jul 17, 2010
Posts: 56
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: guestbook, looping, beans and JSTL