JSP EL:为什么对于未声明的变量,not操作符的计算结果为true ?



我有下面一段求值为true的代码:

<c:choose>
    <c:when test="${not isAddressNotFound}">
            <%-- Always evaluates to true -->
    </c:when>
</c:choose>

但是,isAddressNotFound变量从未在代码中定义。

在计算一个从未定义的变量而不是抛出错误时,这是一个特性吗?如果是这样,这样做的好处是什么?

我认为测试是否定义了一个变量的更好方法是标签

<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>

可以和

一起使用
<logic:present name="isAddressNotFound">
    User object exists.
</logic:present>

<logic:notPresent name="isAddressNotFound">
    User object does not exists.
</logic:notPresent>

为了完全完成你的目标。

最新更新