...">

Don't get "index" value from for loop into if loop in JSP

The my if statement always evaluates to false and is not included in the block <span>

. Because of this, I can't get the "index" value in the if condition, I've tried every thing adding C # index and%. Can anyone suggest a solution?

<c:forEach var="index" begin="1" end="<%=a%>" step="1">
    <s:if test="index == 1">
        <span class="currentpage"><b>${page_id}</b></span>
    </s:if>
    <s:else>
        <a href="searchAction.html?page_id=${index}&searchString=${searchString}" class="paginglinks">${index}</a>
    </s:else>
</c:forEach>

      

0


source to share


4 answers


got it actully it's some kind of tag conflict

it should be like



<c:forEach var="index" begin="1" end="<%=a%>" step="1" varStatus="status">
                            <c:choose>
                            <c:when test="${page_id==index}">                       
                                <span class="currentpage"><b>${page_id}</b></span>
                            </c:when>
                            <c:otherwise>
                            <a href="searchAction.html?page_id=${index}&searchString=${searchString}" class="paginglinks">${index}</a>
                            </c:otherwise>
                            </c:choose>
                            </c:forEach>

      

+1


source


The conflict is that in the first post you mix

  • JSTL Tags (c: forEach)
  • Disables (s: if) tags

Your suggested solution works because you now have

  • JSTL Tags (c: forEach)
  • JSTL tags again (c: when)


Another good solution would be

  • Struts tags (s: iterator)
  • Loops Struts tags (s: if)

Generally speaking, the use of tags from multiple technologies is expected to be problematic.

+1


source


The test value is not evaluated, it is just a line on the page.

Edit you are using strut syntax.

Add "% {}", for example:

<s:if test="%{index == 1}">

      

0


source


use

 test="${index == 1}"

      

or try using varStatus attribute, so ...

<c:forEach var="index" varStatus="status" begin="1" end="<%=a%>" step="1">

 <s:if test="${status.count == 1}">
  <span class="currentpage"><b>${page_id}</b></span>
 </s:if>
 <s:else>
  <a href="searchAction.html?page_id=${index}&searchString=${searchString}" class="paginglinks">${index}</a>
 </s:else>
</c:forEach>

      

0


source







All Articles