没有从for循环中获取'index'值到JSP中的if循环

时间:2022-09-26 23:31:06

My if statement is always evaluating to false and not entering the <span> block. Because of which, I'm not able to get the value of "index" in the if condition, I've tried every thing appending index with # and %. Can anybody suggest the solution?

我的if语句总是评估为false而不是输入块。因此,我无法在if条件中获得“index”的值,我已尝试使用#和%追加索引的所有内容。有人可以提出解决方案吗?

<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>

4 个解决方案

#1


1  

got it actully it is some conflict in the tags

实际上它是标签中的一些冲突

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>

#2


1  

The conflict is that at the first post you are mixing

冲突是你在混合的第一篇文章

  • JSTL tags (the c:forEach)
  • JSTL标签(c:forEach)

  • Struts tags (the s:if)
  • Struts标签(s:if)

Your proposed solution works because you now have

您提出的解决方案有效,因为您现在有

  • JSTL tags (the c:forEach)
  • JSTL标签(c:forEach)

  • JSTL tags again (the c:when)
  • 再次使用JSTL标签(c:when)

Another good solution would be

另一个好的解决方案是

  • Struts tags (the s:iterator)
  • Struts标签(s:iterator)

  • Struts tags again (the s:if)
  • 再次使用Struts标签(s:if)

Generally speaking, using tags from multiple technologies is expected to be problematic.

一般而言,使用来自多种技术的标签预计会有问题。

#3


0  

use

 test="${index == 1}"

or try using the varStatus attribute so...

或者尝试使用varStatus属性,这样......

<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>

#4


0  

The test value isn't evaluatable, it's just a string to the page.

测试值不可评估,它只是页面的一个字符串。

Edit, you have you use strut's syntax.

编辑,你有使用strut的语法。

Add "%{}", like so:

添加“%{}”,如下所示:

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

#1


1  

got it actully it is some conflict in the tags

实际上它是标签中的一些冲突

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>

#2


1  

The conflict is that at the first post you are mixing

冲突是你在混合的第一篇文章

  • JSTL tags (the c:forEach)
  • JSTL标签(c:forEach)

  • Struts tags (the s:if)
  • Struts标签(s:if)

Your proposed solution works because you now have

您提出的解决方案有效,因为您现在有

  • JSTL tags (the c:forEach)
  • JSTL标签(c:forEach)

  • JSTL tags again (the c:when)
  • 再次使用JSTL标签(c:when)

Another good solution would be

另一个好的解决方案是

  • Struts tags (the s:iterator)
  • Struts标签(s:iterator)

  • Struts tags again (the s:if)
  • 再次使用Struts标签(s:if)

Generally speaking, using tags from multiple technologies is expected to be problematic.

一般而言,使用来自多种技术的标签预计会有问题。

#3


0  

use

 test="${index == 1}"

or try using the varStatus attribute so...

或者尝试使用varStatus属性,这样......

<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>

#4


0  

The test value isn't evaluatable, it's just a string to the page.

测试值不可评估,它只是页面的一个字符串。

Edit, you have you use strut's syntax.

编辑,你有使用strut的语法。

Add "%{}", like so:

添加“%{}”,如下所示:

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