开发者

how to iterate a arraylist of object

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜