<%! 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页面输出not hello?为什么它不给hello1作为输出?
答案 0 :(得分:3)
因为${x}
不评估本地变量和实例变量。它查找页面,然后是request-,然后是session-,然后是应用程序范围的名为“x”的属性。如果您使用
<% pageContext.setAttribute("x", 5) %>
或者,因为应该避免使用scriptlet,因此更加清晰:
<c:set var="x" value="5" />