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

自作多情 提交于 2019-12-03 18:26:19

问题


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}"> 

回答1:


This look like a duplicate of JSTL conditional check.

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

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



回答2:


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)}">



回答3:


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')}">



回答4:


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

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


来源:https://stackoverflow.com/questions/8355787/how-do-i-check-two-conditions-in-one-cif

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!