%@ page import="java.util.*" %> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/ea/core" %>
The Conditional operator ?: can be used as a short cut for an if/else statement. A JSTL conditional tag can also be used to verify the test condition.
<% request.setAttribute("true", "true"); %> <% request.setAttribute("false", "false"); %> <% request.setAttribute("ifResult", "IF result"); %> <% request.setAttribute("elseResult", "ELSE result"); %> <% request.setAttribute("myDate", new Date()); %>Here are some examples:
Operation | Result |
---|---|
|
|
|
|
<c:if test="$true == true"> IF result </jx:if> |
|
<c:if test="$false == true"> IF result </jx:if> |
|
<c:if test="$myDate.year == 101"> 1900 + 101 = 2001 </jx:if> |