91

Is this correct?

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

Or could I do this?

<c:if test="${!theBooleanVariable}">It's false!</c:if>
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
wiki
  • 3,049
  • 3
  • 18
  • 13

3 Answers3

125

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>
Romain Linsolas
  • 73,921
  • 45
  • 197
  • 265
21

Both works. Instead of == you can write eq

kiritsuku
  • 51,545
  • 18
  • 109
  • 133
4

You can check this way too

<c:if test="${theBooleanVariable ne true}">It's false!</c:if>
Shams
  • 527
  • 7
  • 15