0

Iam getting the status message from the action class.Based on the status message iam displaying the two different images.

If the Status message is "Acces denied" then it show one image in the JSP page. Else we want to show an different Image.

4

3 回答 3

6

令人惊讶的是,JSTL有文档,并且有官方教程。谷歌是你最好的朋友。

您正在寻找 c:choose、c:when 和 c:otherwise:

<c:choose>
    <c:when test="${status.message == 'Access Denied'}">
        ...
    </c:when>
    <c:otherwise>
        ...
    </c:otherwise>
</c:choose>
于 2013-08-21T10:26:52.963 回答
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>

有关更多详细信息,请参阅此链接

于 2013-08-21T10:26:11.987 回答
0

JSTL 带有<c:choose>,<c:when><c:otherwise>标签来实现if-then-elseJSP 中的类型逻辑。查看JSTL Core 选择标签以获取基本示例。

<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>
于 2013-08-21T10:24:58.700 回答