作爲每documentation,所述fn:length()
僅適用於String
(這將返回String#length()
方法的值)和上Collection
(這將返回Collection#size()
方法的值)。
但是,您好像要通過號碼。一個整數或其他東西。 fn:length()
不適用於數字,並且總是會給出false
,而不考慮數字的值。
如果您要檢查,如果事情是null
,那麼就這樣做:
<c:choose>
<c:when test="${studentData.rollNumber == null}">Found Nothing</c:when>
<c:otherwise>Found something</c:otherwise>
</c:choose>
或者,如果你想檢查數的值是0
,然後就去做
請注意,empty
檢查工作同樣好,這是無論它是一個數字,字符串或集合。任何是null
或fn:length()
的0
將評估true
。
<c:choose>
<c:when test="${empty studentData.rollNumber}">Found Nothing</c:when>
<c:otherwise>Found something</c:otherwise>
</c:choose>
你也可以使用'$ {空studentData.rollNumber}'。 – BalusC 2011-06-07 19:46:49