开发者

how to iterate a arraylist of object

开发者 https://www.devze.com 2022-12-27 06:16 出处:网络
i m using dao design pattern in which i m returning a arraylist object ,inside objecti can fetch by typecasting object into cl开发者_开发技巧ass and acees the getters like object.getName(),i want to i

i m using dao design pattern in which i m returning a arraylist object ,inside object i can fetch by typecasting object into cl开发者_开发技巧ass and acees the getters like object.getName(),i want to itearate using a jstl tags.how can i do that.


<c:forEach items="${yourArrayList}" var="item">
    <c:out value="${item.name}" />
</c:forEach>

The objects you put in your collection should conform to the JavaBeans specification (for ex. all of their properties should be accessible via getter methods).

${yourArrayList} is actually a request attribute that you have put from a servlet and then forwarded to the jsp.


Ok with Bozho.

I will just say that if you redirect a servlet to jsp (which is better than calling dao from scriptlets...) don't forget to put your object that will be used in jstl in a pagecontext scope like request or session. Without that jstl lib would never find your object...

0

精彩评论

暂无评论...
验证码 换一张
取 消