jstl / jsp - 遍历bean的向量 [英] jstl/jsp - iterating over a vector of beans
问题描述
我有一个bean矢量,用于保存我想在jsp页面中显示的信息。我目前只是使用标准的java表达式来显示它,我想研究使用jstl来分离问题。这有可能,怎么样?我一直在谷歌搜索,但我似乎找不到任何东西。
I have a vector of beans that holds information I want to display in my jsp page. I'm currently just using standard java expressions to display this, I want to look into using jstl to separate concerns. Is this possible, and how? I've been googling but I can't seem to find anything.
推荐答案
我认为你所寻找的是的 < c:foreach> 标记。
I think that what you are looking for is the < c:foreach > tag.
例如,在MyClass实例上打印myInt属性值(定义如下):
for example, printing the value myInt property on instances of MyClass (defined below):
<c:foreach items="${vectors name}" var="pos" >
<!-- print the value of myInt for each position of the array.
Method getMyInt() must exist in pos object.-->
<c:out value="${pos.myInt}"/>
<!-- print the value of myInt for each composed instance.
Method getRelatedInstance() must exist in pos object. -->
<c:out value="${pos.relatedInstance.myInt}"/>
</c:foreach>
其中矢量名称是矢量的名称,例如,做一个
where vector name is the name of the vector ,for example, after doing a
假设你有一个类myClass。
Suppose you have a class myClass.
public class MyClass{
private MyClass relatedInstance;
//some members and methods
public int getMyInt(){
//return something
}
public MyClass getRelatedInstance(){
return this.relatedInstance;
}
List<myClass> my_vector = getFilledList();
request.setAttribute("vectors name",my_vector)
这篇关于jstl / jsp - 遍历bean的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!