March 2, 2011

JSTL 1.1 - <c:choose>, <c:when> and <c:otherwise> example


<c:set var="userType" scope="request" value="none" />
<c:choose>
   <c:when test="${requestScope.userType == 'regular'}">
      Welcome! You are a regular user.
   </c:when>
   <c:when test="${requestScope.userType == 'premium'}">
      Welcome! You are a premium user.
   </c:when>
   <c:otherwise>
      Welcome! You are not a registered user.
   </c:otherwise>
</c:choose>

prints,

Welcome! You are not a registered user.

No comments:

Post a Comment