Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JSP中的条状条件执行_Jsp_Stripes - Fatal编程技术网

JSP中的条状条件执行

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

我想测试n actionBean变量的值,并根据结果打印不同的消息。我现在的代码是:

<% 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>