如何使用JSTL的c标记验证String为null还是为空?
您可以为此使用
empty关键字
<c:if>:
<c:if test="${empty var1}"> var1 is empty or null.</c:if><c:if test="${not empty var1}"> var1 is NOT empty or null.</c:if>或
<c:choose>:
<c:choose> <c:when test="${empty var1}"> var1 is empty or null. </c:when> <c:otherwise> var1 is NOT empty or null. </c:otherwise></c:choose>或者,如果您不需要有条件地渲染一堆标签,因此只能在tag属性中检查它,则可以使用EL条件运算符
${condition? valueIfTrue :valueIfFalse}:<c:out value="${empty var1 ? 'var1 is empty or null' : 'var1 is NOT empty or null'}" />要了解有关这些
${}内容的更多信息(表达语言,它是与JSTL分开的主题),请点击此处。


