getting value from an object in jstl, getting property name from a list

2k views Asked by At

I am new to JSTL, I understand that to get field value we can use the following code:

<c:out value="${empDetails.id}" />
<c:out value="${empDetails.name}" />
<c:out value="${empDetails.dept}" />
<c:out value="${empDetails.locn}" />

I have a requirement to get the list of property names to be shown in UI in an arrayList, in JSP I want to iterate and get the value from empDetails.

I want to write something like below:

<c:forEach items="${list}" var="item">
    <c:out value="${empDetails}" property="${item}/>
</c:forEach>

The List will contain values "id","name", "locan", "dept" etc.

Could some one please help how to do it?

1

There are 1 answers

0
user3305063 On

I found answer in one of the stackoverflow questions,

<c:forEach items="${list}" var="item">
    <c:out value="${empDetails[item]}" />
</c:forEach>