JSP中的条状条件执行
我想测试n actionBean变量的值,并根据结果打印不同的消息。我现在的代码是:JSP中的条状条件执行,jsp,stripes,Jsp,Stripes,我想测试n actionBean变量的值,并根据结果打印不同的消息。我现在的代码是: <% if ( ${actionBean.server.virtual} == true ) { %> This is a virtual machine.<br/> <% } else { %> This is not a virtual machine.<br/> <% } %> 尽管我知道这会起作用,但它不是很人性化。您将Java脚本与JSTL
<% if ( ${actionBean.server.virtual} == true ) { %>
This is a virtual machine.<br/>
<% } else { %>
This is not a virtual machine.<br/>
<% } %>
尽管我知道这会起作用,但它不是很人性化。您将Java脚本与JSTL混合使用。选择JSTL并使用jsp核心标记库
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--Your jsp should start with the taglib declaration above.--%>
<c:choose>
<c:when test="${actionBean.server.virtual}">
This is a virtual machine.<br/>
</c:when>
<c:otherwise>
This is not a virtual machine.<br/>
</c:otherwise>
</c:choose>
这是一个虚拟机。
这不是虚拟机。
这正是我所需要的——效果非常好!(这就是为什么永远不要让系统管理员接近Java代码的部分原因。)
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--Your jsp should start with the taglib declaration above.--%>
<c:choose>
<c:when test="${actionBean.server.virtual}">
This is a virtual machine.<br/>
</c:when>
<c:otherwise>
This is not a virtual machine.<br/>
</c:otherwise>
</c:choose>