2013-08-21 23 views
0

Iam從操作類中獲取狀態消息。基於顯示兩個不同圖像的狀態消息iam。如何使用If .....否則使用JSP頁面中的JSTl標籤

如果狀態消息是「訪問被拒絕」,那麼它會在JSP頁面中顯示一個圖像。 否則我們想顯示不同的圖像。

+0

我找遍所有很多都僅僅具有用於代碼「IF」語句,沒有用於否則無碼聲明。 –

+0

參考此[鏈接](http://www.datadisk.co.uk/html_docs/jsp/jsp_using_jstl.htm) –

+0

請參閱此 - http://stackoverflow.com/questions/4587397/how-to-use-if -else選項功能於JSTL?RQ = 1 – Saurabh

回答

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> 
5

不存在一樣,如果別人在JSTL的而不是JSTL條件下提供以下

<c:choose> 
    <c:when test="${condition1}"> 
    ... 
    </c:when> 
    <c:when test="${condition2}"> 
    ... 
    </c:when> 
    <c:otherwise> 
    ... 
    </c:otherwise> 
</c:choose> 

有關詳細信息,請參閱本link

6

JSTL的,奇怪的是,is documented,並具有official tutorial 。 Google是你最好的朋友。

您正在尋找C:選C:當和c:否則:

<c:choose> 
    <c:when test="${status.message == 'Access Denied'}"> 
     ... 
    </c:when> 
    <c:otherwise> 
     ... 
    </c:otherwise> 
</c:choose> 
相關問題