• 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>标签之后。

  • 相关阅读:
    win10和Ubuntu双系统安装过程中遇到的问题
    python中矩阵的用法
    python中yield的用法
    python中的*和**的用途
    python函数后面有多个括号怎么理解?
    keras中的重要函数
    机器学习的常见算法
    agent page
    Spring常用注解介绍【经典总结】
    Spring配置中<context:annotation-config> VS <context:component-scan>
  • 原文地址:https://www.cnblogs.com/a294098789/p/5302745.html
Copyright © 2020-2023  润新知