JSP/JSTL:';2>;10';计算结果为true
我有一个非常简单的自定义JSP标记,用于生成分页链接。大致上是这样的:JSP/JSTL:';2>;10';计算结果为true,jsp,jstl,jsp-tags,Jsp,Jstl,Jsp Tags,我有一个非常简单的自定义JSP标记,用于生成分页链接。大致上是这样的: <span id="${id}" class="paginationLinks ${cssClass}"> <c:if test="${currentPage gt 1}"> <!-- Links to previous page(s) --> </c:if> <span class="paginationCurrentPage"&
<span id="${id}" class="paginationLinks ${cssClass}">
<c:if test="${currentPage gt 1}">
<!-- Links to previous page(s) -->
</c:if>
<span class="paginationCurrentPage">
Page ${currentPage}
[DEBUG: current=${currentPage},
total=${totalPages},
show=${currentPage lt totalPages}
inverse=${currentPage gt totalPages}]
</span>
<c:if test="${currentPage lt totalPages}">
<!-- Links to next page(s) -->
</c:if>
</span>
currentPage
和totalPages
都是long
类型的请求属性,通过声明的标记属性传递给标记。那么,我做了什么错事来产生像2>10==true
这样疯狂的输出呢
更新
如果我在比较中用文本
10
替换totalPages
,它可以正常工作,但这并不能解决问题。找到了解决方案。我需要在标记属性上显式声明类型,如:
<%@ attribute name="currentPage" required="true" type="java.lang.Long" %>
<%@ attribute name="totalPages" required="true" type="java.lang.Long" %>
我怀疑在没有声明类型的情况下,这两个属性都被解释为字符串,并且标记正在对数字的字符串值进行词典比较。我假设10
的文本值起作用,因为JSP解释器将其识别为正确的数字类型,然后自动将比较中的其他参数转换为匹配
长话短说,始终在标记属性上声明
类型
。否则会发生非常混乱的事情。找到解决方案。我需要在标记属性上显式声明类型,如:
<%@ attribute name="currentPage" required="true" type="java.lang.Long" %>
<%@ attribute name="totalPages" required="true" type="java.lang.Long" %>
我怀疑在没有声明类型的情况下,这两个属性都被解释为字符串,并且标记正在对数字的字符串值进行词典比较。我假设10
的文本值起作用,因为JSP解释器将其识别为正确的数字类型,然后自动将比较中的其他参数转换为匹配
长话短说,始终在标记属性上声明类型
。否则会发生非常混乱的事情