Exclusive OR (XOR) in EL

Is there any way to do exclusive or in EL? I have two variables. I want to check if only one of them is empty at a time. I understand that I can do this manually by doing the following, but I wanted to know if there is an EL keyword for it?

<c:if test="${(!empty var1 and empty var2) or (empty var1 and !empty var2}> ----Do something here.. </c:if> 
+4
source share
2 answers

EL does not have an XOR operator , but since both expressions return a boolean already, just compare them with != .

 <c:if test="${empty var1 != empty var2}"> ----Do something here.. </c:if> 
+5
source

The logical XOR is the same as "not equal", so use this:

 <c:if test="${(empty var1) != (empty var2)}> ----Do something here.. </c:if> 

Unable to find XOR operator here .

+1
source

Source: https://habr.com/ru/post/1434253/


All Articles