<%! 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作为输出?
发布于 2013-05-12 16:11:48
因为${x}不计算局部变量和实例变量。它查找一个页面,然后是请求,然后是会话,然后是名为"x“的应用程序范围的属性。上面的代码如果你使用
<% pageContext.setAttribute("x", 5) %>或者,更干净,因为应该避免scriptlet:
<c:set var="x" value="5" />https://stackoverflow.com/questions/16505387
复制相似问题