zl程序教程

您现在的位置是:首页 >  后端

当前栏目

jsp中如何用jstl实现if(){}else if(){}else{}

JSP 实现 如何 if Else JSTL
2023-09-14 09:07:42 时间
<c:choose>
<c:when test="${条件}">
情况1...........
</c:when>
<c:when test="${条件}">
 情况2...........
</c:when>
<c:otherwise>
否则。。。。。
</c:otherwise>
</c:choose>

jstl中if语句

<c:if>标签计算表达式,只有当表达式的值为true,则显示其主体内容。

属性:

<c:if>标签具有以下属性:

属性描述必需默认
test 条件计算 Yes None
var 变量名称的存储条件的结果 No None
scope 变量的范围的存储条件的结果 No page

例子:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:if> Tag Example - www.yiibai.com</title>
</head>
<body>
<c:set var="salary" scope="session" value="${2000*2}"/>
<c:if test="${salary > 2000}">
   <p>My salary is: <c:out value="${salary}"/><p>
</c:if>
</body>
</html>

这将产生以下结果:

My salary is: 4000