语法格式
<c:choose>
<c:when test=””>
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
属性
其中<c:choose>和<c:otherwise>标签没有属性,<c:when>标签只有一个属性,为test属性,该属性的作用是“条件”。
Demo
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>c:choose 简单应用</title>
</head>
<body>
<c:set var="score" scope="session" value="${60}"/>
<p>你的成绩为 : <c:out value="${ score }"/></p>
<c:choose>
<c:when test="${ score < 60}">
不及格。
</c:when>
<c:when test="${ score >= 60}">
及格了。
</c:when>
<c:otherwise>
错了!
</c:otherwise>
</c:choose>
</body>
</html>
运行结果
你的成绩为:60
及格了。
及格了。