jstl - how to access array list in jsp , if i pass bean -


i new jstl. how can use jstl <c:foreach> inside jsp if pass below sample bean

class b{     private string value="";     private arraylist arrayvals;     public string getvalue(){         return value;     }     public string getarrayvals(){         return arrayvals;     } } 

i pass bean "b" only. tried below, jsp not compiled. please me.

<c:foreach items="${b.getarrayvals}" var="book">      <c:out value="{book.title}"/>  </c:foreach> 

first of all, getarrayvals() should spelt getarrayvals(), , should return list, not string, obviously.

now suppose servlet or action sets attribute "b" of type b :

request.setattribute("b", thebinstance); 

and forwards jsp, can access list in attribute "b" this:

${b.arrayvals} 

you must refer b instance name of request attribute, not class name. if name attribute foo, use must use ${foo.arrayvals}. print tostring of list. if want element @ index 3 of list, can use

${b.arrayvals[3]} 

and if want iterate on list elements, use c:foreach construct:

<c:foreach items="${b.arrayvals}" var="element">     element value ${element} <br/> </c:foreach> 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -