【发布时间】:2019-07-30 16:11:08
【问题描述】:
我是JSTL 的新手,我知道要获取字段值,我们可以使用以下代码:
<c:out value="${empDetails.id}" />
<c:out value="${empDetails.name}" />
<c:out value="${empDetails.dept}" />
<c:out value="${empDetails.locn}" />
我需要获取要在 UI 中的 arrayList 中显示的属性名称列表,在 JSP 中我想迭代并从 empDetails 中获取值。
我想写如下内容:
<c:forEach items="${list}" var="item">
<c:out value="${empDetails}" property="${item}/>
</c:forEach>
列表将包含值“id”、“name”、“locan”、“dept”等。
有人可以帮忙怎么做吗?
【问题讨论】:
-
感谢回复,对象名称是empDetails,我要打印的字段在列表中。我想将字段名称作为字符串传递。它类似于我们在 java 中使用反射的方式。在您的建议中,“id”是我需要在 jsp 中硬编码的字段名称。但我是动态得到的。
标签: arrays list jstl field jstl-functions