Jsp 比较c:if中的scriptlet变量

Jsp 比较c:if中的scriptlet变量,jsp,jstl,Jsp,Jstl,这里有一些代码 <% String what = (String)session.getAttribute("BANG"); %> <c:set var="bang" value="Song" /> 我将从会话中获取一个字符串,并将其与jstl变量中的字符串进行比较 我试过一个if-in <% if() { %> some text <% } %> 一些文本 也试过 <c:if test="${va1 == va2}" </

这里有一些代码

<% String what = (String)session.getAttribute("BANG"); %>
<c:set var="bang" value="Song" />

我将从会话中获取一个字符串,并将其与jstl变量中的字符串进行比较

我试过一个if-in

<% if() { %> some text <% } %> 
一些文本
也试过

<c:if test="${va1 == va2}" </c:if>

对于初学者,建议停止使用scriptlet,即那些
东西。它们与JSTL/EL不能很好地协同工作。你应该选择其中之一。由于Scriptlet已经存在了十年,因此停止使用它们是有意义的


回到你的具体问题,下面的脚本

因此,这应该可以为您做到:

<c:if test="${BANG == 'Song'}">
    This block will be executed when the session attribute with the name "BANG"
    has the value "Song".
</c:if>
另见:

我不清楚你想要完成什么。顶部的第一行创建一个脚本变量,并从会话范围变量中为其赋值。第二行设置页面范围变量的值。在第三行和第四行中,您试图测试什么条件?请不要将“scriptlets”与“javascript”混用。这些绝对不一样。我修正了(最初非常混乱的)问题标题。
${BANG}
<c:if test="${BANG == 'Song'}">
    This block will be executed when the session attribute with the name "BANG"
    has the value "Song".
</c:if>
<c:set var="bang" value="Song" />
<c:if test="${BANG == bang}">
    This block will be executed when the session attribute with the name "BANG"
    has the same value as the page attribute with the name "bang".
</c:if>