简体   繁体   English

如何迭代对象的数组列表

[英]how to iterate a arraylist of object

我使用的是dao设计模式,其中我返回了一个arraylist对象,在对象内部我可以通过将对象类型转换为类来获取对象,并像object.getName()那样获取getter,我想使用jstl标签进行编程。我该怎么做。

<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). 您放入集合中的对象应符合JavaBeans规范(例如,应通过getter方法访问其所有属性)。

${yourArrayList} is actually a request attribute that you have put from a servlet and then forwarded to the jsp. ${yourArrayList}实际上是您从Servlet放入的请求属性,然后转发给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. 我只是说,如果将servlet重定向到jsp(比从scriptlet调用dao更好...),请不要忘记将要在jstl中使用的对象放在诸如请求或会话之类的pagecontext范围内。 Without that jstl lib would never find your object... 没有这个jstl lib,就永远找不到您的对象...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM