您的位置:首页 > Web前端 > JavaScript

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: