小白教程
所有教程
关于
Search
172.70.126.178
172.70.126.178
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Jstl core choose tag”的源代码
本页内容
上一节:
Jstl_core_if_tag
下一节:
Jstl_core_import_tag
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:<c:otherwise>}}[[Category:jsp jstl|8]] = <c:choose>, <c:when>, <c:otherwise> 标签 = [[jsp jstl|JSP 标准标签库]] <c:choose>标签与Java switch语句的功能一样,用于在众多选项中做出选择。 switch语句中有case,而<c:choose>标签中对应有<c:when>,switch语句中有default,而<c:choose>标签中有<c:otherwise>。 === 语法格式 === <sample title="" desc="" lang="jsp" hererun="1"> <c:choose> <c:when test="<boolean>"> ... </c:when> <c:when test="<boolean>"> ... </c:when> ... ... <c:otherwise> ... </c:otherwise> </c:choose> </sample> === 属性 === * <c:choose>标签没有属性。 * <c:when>标签只有一个属性,在下表中有给出。 * <c:otherwise>标签没有属性。 <c:when>标签的属性如下: {| class="table table-striped table-hover" ! '''属性''' ! '''描述''' ! '''是否必要''' ! '''默认值''' |- | test | 条件 | 是 | 无 |} == 实例演示 == <sample title="" desc="" lang="jsp" hererun="1"> <%@ 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="salary" scope="session" value="${2000*2}"/> <p>你的工资为 : <c:out value="${salary}"/></p> <c:choose> <c:when test="${salary <= 0}"> 太惨了。 </c:when> <c:when test="${salary > 1000}"> 不错的薪水,还能生活。 </c:when> <c:otherwise> 什么都没有。 </c:otherwise> </c:choose> </body> </html> </sample> 运行结果如下: <sample title="" desc="" lang="jsp" hererun="1"> 你的工资为 : 4000 不错的薪水,还能生活。 </sample> [[jsp jstl|JSP 标准标签库]]
返回至“
Jstl core choose tag
”。
上一节:
Jstl_core_if_tag
下一节:
Jstl_core_import_tag