如何在 JSP 中应用选择标签?
<c:choose> 类似于 Java 中的 switch 语句,它允许你在多个选项之间选择。switch 语句有 case 语句,<c:choose> 标签有 <c:when> 标签。正如 switch 语句有 default 子句来指定默认操作,<c:choose> 也有 <c:otherwise> 作为默认子句。
属性
<c:choose> 标签没有任何属性。
<c:when> 标签有一个属性,如下所示。
<c:otherwise> 标签没有任何属性。
<c:when> 标签有以下属性 -
| 属性 | 说明 | 必需 | 默认 |
|---|---|---|---|
| test | 要评估的条件 | 是 | 无 |
示例
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<html>
<head>
<title><c:choose> Tag Example</title>
</head>
<body>
<c:set var = "salary" scope = "session" value = "${2000*2}"/>
<p>Your salary is : <c:out value = "${salary}"/></p>
<c:choose>
<c:when test = "${salary <= 0}">
Salary is very low to survive.
</c:when>
<c:when test = "${salary > 1000}">
Salary is very good.
</c:when>
<c:otherwise>
No comment sir...
</c:otherwise>
</c:choose>
</body>
</html>以上代码将生成以下结果 -
Your salary is : 4000 Salary is very good.
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP