tv3free
tv3free

Reputation: 77

How do I add for loop index to the JSP variable

How do I add logic to do for loop only if ${link[i].alt} is not empty?
How to add index to the jsp var ...like ${link${i}.credit}??

<c:forEach var="i" begin="1" end="6">
    <li>${i}
        <a class="lnid-sec1_lnk${i}" href="${link.href}">
            <div class="l-wrapper">
                <img data-src="${link1.credit}" src="${link1.credit}" alt="${link1.alt}" width="100">
                <div class="team-name">
                    <span>${link1.alt}</span>
                </div>
            </div>
        </a>
    </li>
</c:forEach>

Upvotes: 1

Views: 1144

Answers (3)

vivekpansara
vivekpansara

Reputation: 899

For not empty you can use this

<c:if test="${!empty link[i].alt}"></c:if>

Upvotes: 0

Nimesh
Nimesh

Reputation: 802

Ans:1

<c:if test="${!empty link[i].alt}"></c:if>

Ans: 2

<c:set var="your_var" value="${link[i.index].credit}"/>

Upvotes: 1

user4447899
user4447899

Reputation: 332

add varStatus

so

<c:forEach var="i" begin="1" end="6" varStatus="yourIndex">

Then

(${yourIndex.index}) contains the index

Upvotes: 1

Related Questions