How do I check two conditions in one ?

2019-01-31 05:17发布

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 el
4条回答
The star\"
2楼-- · 2019-01-31 05:48

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楼-- · 2019-01-31 05:51

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}">
查看更多
贼婆χ
4楼-- · 2019-01-31 05:52

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')}">
查看更多
可以哭但决不认输i
5楼-- · 2019-01-31 06:02

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

<c:if test="${sessionScope['roleid'] == 1 || sessionScope['roleid'] == 4}">
查看更多
登录 后发表回答