JSTL标签中c:choose,c:when,c:otherwise 可以实现if...else if..else的用法
2016-11-13 13:54
501 查看
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'jstl1.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<%-- <h4>c:out</h4>
<c:set var="info" value="JSTL标签" scope="request"></c:set>
Book:${requestScope.info}<br/><br/>
Book:<c:out value="${requestScope.info}"></c:out><br/>
<c:set var="year" value="1997" scope="session"></c:set>
Book:${sessionScope.year}<br/><br/>
Book:<c:out value="${sessionScope.year}"></c:out><br/>
<c:remove var="year" scope="session"/>
Book:${sessionScope.year}<br/><br/>
Book:<c:out value="${sessionScope.year}"></c:out>
<h4>c:if</h4>
<c:set value="20" var="age" scope="request"></c:set>
<c:if test="${requestScope.age>18}" var="isAdult" scope="request">已经成年了</c:if>
<c:out value="${requestScope.isAdult}"></c:out> --%>
<h4>c:choose,c:when,c:otherwise 可以实现if...else if..else</h4>
<c:set value="20" var="age" scope="request"></c:set>
<c:choose>
<c:when test="${requestScope.age>60}">老年</c:when>
<c:when test="${requestScope.age>40}">中年</c:when>
<c:when test="${requestScope.age>18}">青年</c:when>
<c:otherwise>幼年</c:otherwise>
</c:choose>
</body>
</body>
</html>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'jstl1.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<%-- <h4>c:out</h4>
<c:set var="info" value="JSTL标签" scope="request"></c:set>
Book:${requestScope.info}<br/><br/>
Book:<c:out value="${requestScope.info}"></c:out><br/>
<c:set var="year" value="1997" scope="session"></c:set>
Book:${sessionScope.year}<br/><br/>
Book:<c:out value="${sessionScope.year}"></c:out><br/>
<c:remove var="year" scope="session"/>
Book:${sessionScope.year}<br/><br/>
Book:<c:out value="${sessionScope.year}"></c:out>
<h4>c:if</h4>
<c:set value="20" var="age" scope="request"></c:set>
<c:if test="${requestScope.age>18}" var="isAdult" scope="request">已经成年了</c:if>
<c:out value="${requestScope.isAdult}"></c:out> --%>
<h4>c:choose,c:when,c:otherwise 可以实现if...else if..else</h4>
<c:set value="20" var="age" scope="request"></c:set>
<c:choose>
<c:when test="${requestScope.age>60}">老年</c:when>
<c:when test="${requestScope.age>40}">中年</c:when>
<c:when test="${requestScope.age>18}">青年</c:when>
<c:otherwise>幼年</c:otherwise>
</c:choose>
</body>
</body>
</html>
相关文章推荐
- JSTL(JSP标准标签库)常用标签用法 (流程控制:if,choose,when,otherwise; 迭代:forEach)
- Mybatis 动态加载sql when otherwise choose 理解成if else 条件中可以把传来的参数当变量
- jstl 的if else <c:choose><c:when test="">如果</c:when><c:otherwise>否则</c:otherwise></c:choose>
- JSTL标签用法:<c:choose><c:forEach><c:if><c:when><c:set>
- jstl标签库:choose、when、otherwise标签
- JSTL标签用法:<c:choose><c:forEach><c:if><c:when><c:set>
- JSTL:--choose,when,otherwise标签实例
- JSTL标签用法:<c:choose><c:forEach><c:if><c:when><c:set>
- JSTL标签用法:<c:choose><c:forEach><c:if><c:when><c:set>
- JSTL-core核心代码标签库中的forEach,remove, forTokens,choose,when,otherwise,redirect 标签
- jsp中jstl标签的类似 if - else 语句 的语法c:choose
- JSTL标签之<c:choose><c:when><c:otherwise>标签
- JSTL标签参考手册,JSTL标签用法:<c:choose><c:forEach><c:if><c:when><c:set>
- jsp页面中jstl标签详解 包括< c:choose> <c:when> <c:otherwise>
- 如何实现JSTL if else if else 的jsp标签
- JSTL标签库:choose、when、otherwise、set标签
- 【转】JSTL标签用法:<c:choose><c:forEach><c:if><c:when><c:set>
- java web javaEE ,jsp EL表达式和JSTL标签if-else if-else四种用法
- 如何在JSP页面中使用JSTL标签实现if-else判断
- 如何在JSP页面中使用JSTL标签实现if和if-else判断