开发者

How to check a boolean condition in EL?

开发者 https://www.devze.com 2023-01-19 12:40 出处:网络
Is this correct? <c:if test=\"${theBooleanVariable == false}\">It\'s false!&l开发者_运维问答t;/c:if>

Is this correct?

<c:if test="${theBooleanVariable == false}">It's false!&l开发者_运维问答t;/c:if>

Or could I do this?

<c:if test="${!theBooleanVariable}">It's false!</c:if>


You can have a look at the EL (expression language) description here.

Both your code are correct, but I prefer the second one, as comparing a boolean to true or false is redundant.

For better readibility, you can also use the not operator:

<c:if test="${not theBooleanVariable}">It's false!</c:if>


Both works. Instead of == you can write eq


You can check this way too

<c:if test="${theBooleanVariable ne true}">It's false!</c:if>
0

精彩评论

暂无评论...
验证码 换一张
取 消