user2515189
user2515189

Reputation: 569

<c:forEach> tag is giving the list values multiple times repeatedly in my jsp

below is my code in jsp

<c:forEach var="list" items="${historyList}" varStatus="iter">
<tr>
<td>${list[0]}</td>
<td>${list[1]}</td>
<td>${list[2]}</td>
</tr>
</c:forEach>

The problem is the above code is giving the list of items correctly.But each value is repeated 6 times.

Output:

 0.456 1234 OK
 0.456 1234 OK
 0.456 1234 OK
 0.456 1234 OK
 0.456 1234 OK
 0.456 1234 OK
 1.209 3457 YES
 // this above row is also 6 times repeating

I am getting all the values but repeatedly getting like above.Please solve my problem.Thank you.

Upvotes: 0

Views: 1269

Answers (1)

fmodos
fmodos

Reputation: 4568

It already is iterating the list, so it is not necessary to access all the items of the array by the specific position ${list[0]}${list[1]}, just access the current one of the iteration like the example below:

<c:forEach var="item" items="${historyList}" varStatus="iter">
<tr>
<td>${item}</td>
</tr>
</c:forEach>

Update

Your code looks fine as the items of historyList are of array type. I think the issue is that the historyList has duplicated items.

Upvotes: 1

Related Questions