簡體   English   中英

JSTL使用腳本

[英]Jstl working with scriptlets

<%! int x=5; %>


        <c:choose>
            <c:when test="${x eq 5}"><p>hello1</p></c:when>            
            <c:when test="${x gt 10}"><p>}hello3</p></c:when>
            <c:otherwise>Value is ${x},Not hello</c:otherwise>
        </c:choose>

為什么上面的代碼從我的jsp頁面中給出的結果不是hello?為什么沒有給出hello1的輸出?

因為${x}不評估局部變量和實例變量。 它尋找一個頁面,然后是請求,然后是會話,然后是應用程序范圍的屬性“ x”。 如果您使用了上面的代碼,則可以使用

<% pageContext.setAttribute("x", 5) %>

或者,由於應避免使用腳本,因此更加清潔:

<c:set var="x" value="5" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM