choose标签简介

choose标签包含两个子标签:when标签(必须标签)和otherwise标签(非必须标签),choose标签的作用类似Java中的switch语句,用于做出多项选择,而其子标签when标签则相当于case,otherwise则相当于default。

choose标签的语法













实例代码如下:

  1. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  2. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
  3. <html>
  4. <head>
  5. <title>JSTL标签的使用</title>
  6. </head>
  7. <body>
  8. <%
  9. request.setAttribute("score",88);
  10. %>
  11. <c:if test="${score==80}">
  12. <h2>没问题呀!</h2>
  13. </c:if>
  14. <c:choose>
  15. <c:when test="${score<60}">
  16. <h2>你这个小渣渣!</h2>
  17. </c:when>
  18. <c:when test="${score>=60&&score<80}">
  19. <h2>哎呀,不错哟!</h2>
  20. </c:when>
  21. <c:when test="${score>=80}">
  22. <h2>你好棒棒哦!</h2>
  23. </c:when>
  24. <c:otherwise>
  25. <h2>你的分数可真是太奇葩了!</h2>
  26. </c:otherwise>
  27. </c:choose>
  28. </body>
  29. </html>

运行结果:
image.png