zoukankan      html  css  js  c++  java
  • jstl c:choose>、<c:when>和<c:otherwise>标签

    <c:choose>、<c:when>和<c:otherwise>在一起连用,可以实现Java语言中的if-else语句的功能。例如以下代码根据username请求参数的值来打印不同的结果:

    <c:choose> 

      <c:when test="${empty param.username}">   

        Nnknown user.  

      </c:when> 

      <c:when test="${param.username=='Tom'}">   

        ${param.username} is manager.  

      </c:when> 

      <c:otherwise>   

        ${param.username} is employee.  

      </c:otherwise> 

    </c:choose> 

    以上标签等价于以下Java程序片段:

    <%  

    String username=request.getParameter("username");  

    if(username==null){  

      //对应第一个<c:when>标签的主体  

      out.print("Nnknown user.");  

    }else if(username.equals("Tom")){  

      //对应第二个<c:when>标签的主体  

      out.print(username+" is manager.");  

    }else{  

      //对应<c:otherwise>标签的主体  

      out.print(username+" is employee.");  

    }  

    %> 

    <c:choose>、<c:when>和<c:otherwise>标签的使用必须符合以下语法规则:

    <c:when>和<c:otherwise>不能单独使用,它们必须位于<c:choose>父标签中。

    在<c:choose>标签中可以包含一个或多个<c:when>标签。

    在<c:choose>标签中可以不包含<c:otherwise>标签。

    在<c:choose>标签中如果同时包含<c:when>和<c:otherwise>标签,那么<c:otherwise>必须位于<c:when>标签之后。

  • 相关阅读:
    [转]C# ReportViewer报表 详解
    [转]Java NIO原理图文分析及代码实现
    [转]C#泛型编程
    [转]ASP.NET页面基本对象
    [转]C#中抽象类和接口的异同
    [转]Android进程间通信消息机制及IPC机制实现
    [转]左连接和右连接的区别
    [转]C# 4.0 新特性
    [转]UML类图java代码实现
    [转]Using The Entity Framework With WCF
  • 原文地址:https://www.cnblogs.com/a294098789/p/5302745.html
Copyright © 2011-2022 走看看