【问题标题】:Jstl working with scriptletsJstl 使用脚本
【发布时间】:2013-05-12 08:08:17
【问题描述】:
<%! 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 作为输出?

【问题讨论】:

    标签: java jsp servlets jstl


    【解决方案1】:

    因为${x} 不计算局部变量和实例变量。它查找页面,然后是请求,然后是会话,然后是名为“x”的应用程序范围的属性。如果您使用上面的代码,则可以使用

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

    或者,更简洁,因为应该避免使用 scriptlet:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多