2013-05-12 57 views
0
<%! 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作爲輸出?Jstl使用scriptlets

回答

3

因爲${x}不計算本地和實例變量。它查找頁面,然後請求,然後會話,然後查找名爲「x」的應用程序範圍的屬性。代碼如果您使用

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

,或者更清潔,因爲應該避免小腳本上面會的工作:

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