我从动作类中获取状态消息。基于状态消息iam显示两个不同的图像。
如果Status消息为“Acces denied”,则它会在JSP页面中显示一个图像。 否则,我们想要展示不同的图像。
答案 0 :(得分:6)
令人惊讶的是,JSTL is documented,并且official tutorial。谷歌是你最好的朋友。
你正在寻找c:选择,c:何时和c:否则:
<c:choose>
<c:when test="${status.message == 'Access Denied'}">
...
</c:when>
<c:otherwise>
...
</c:otherwise>
</c:choose>
答案 1 :(得分:5)
没有像jstl中的if else那样的条件而不是jstl提供以下
<c:choose>
<c:when test="${condition1}">
...
</c:when>
<c:when test="${condition2}">
...
</c:when>
<c:otherwise>
...
</c:otherwise>
</c:choose>
有关详细信息,请参阅此link
答案 2 :(得分:0)
JSTL附带<c:choose>
,<c:when>
和<c:otherwise>
标记,以在JSP中实现if-then-else
类型逻辑。查看JSTL Core Choose Tag了解基本示例。
<c:choose>
<c:when test="${a boolean expr}">
<!-- // do something -->
</c:when>
<c:when test="${another boolean expr}">
<!-- // do something else -->
</c:when>
<c:otherwise>
<!-- // do this when nothing else is true -->
</c:otherwise>
</c:choose>