How do I check two or more conditions in one <c:if>?

JstlEl

Jstl Problem Overview


How do I check two conditions in one <c:if>? I tried this, but it raises an error:

<c:if test="${ISAJAX == 0} && ${ISDATE == 0}"> 

Jstl Solutions


Solution 1 - Jstl

This look like a duplicate of https://stackoverflow.com/questions/6219730/jstl-conditinal-check.

The error is having the && outside the expression. Instead use

<c:if test="${ISAJAX == 0 && ISDATE == 0}">

Solution 2 - Jstl

If you are using JSP 2.0 and above It will come with the EL support: so that you can write in plain english and use and with empty operators to write your test:

<c:if test="${(empty object_1.attribute_A) and (empty object_2.attribute_B)}">

Solution 3 - Jstl

Recommendation:

when you have more than one condition with and and or is better separate with () to avoid verification problems

<c:if test="${(not validID) and (addressIso == 'US' or addressIso == 'BR')}">

Solution 4 - Jstl

Just in case somebody needs to check the condition from session.Usage of or

<c:if test="${sessionScope['roleid'] == 1 || sessionScope['roleid'] == 4}">

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSelva Kumar K.P.View Question on Stackoverflow
Solution 1 - Jstlolly_ukView Answer on Stackoverflow
Solution 2 - JstlJules0707View Answer on Stackoverflow
Solution 3 - JstlJoel EstramilView Answer on Stackoverflow
Solution 4 - JstlA_01View Answer on Stackoverflow