2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

Evaluate empty or null JSTL c tags

Need some suggestion to validate if a String is null or empty using the c tags of JSTL.

e.g

<c:out value="${anyString}" />
userimage

You can also able to use below snippet.

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>


<c:if test="${empty fn:trim(var1)}">


</c:if>

userimage

You can use the <c:if> for this:
<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>

Or the <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>

Answer is