2

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?

user3382203
  • 169
  • 1
  • 6
  • 25
user3305063
  • 461
  • 1
  • 5
  • 15
  • Thanks for reply, object name is empDetails, fields what I want to print is in the list. I want to pass the field name as string. It is similar to how we use reflection in java. In your suggestion "id" is field name which I need to hard code in jsp. But I am getting this dynamically. – user3305063 Mar 08 '19 at 15:54

1 Answers1

1

I found answer in one of the stackoverflow questions,

<c:forEach items="${list}" var="item">
    <c:out value="${empDetails[item]}" />
</c:forEach>
user3305063
  • 461
  • 1
  • 5
  • 15