jstl.jsp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  2. <%--
  3. Created by IntelliJ IDEA.
  4. User: 武恒
  5. Date: 2023/2/18
  6. Time: 15:31
  7. To change this template use File | Settings | File Templates.
  8. --%>
  9. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  10. <html>
  11. <head>
  12. <title>JSTL 标签</title>
  13. </head>
  14. <body>
  15. <%
  16. int n = 10;
  17. String[] arr = {"苹果","鸭梨","香蕉","菠萝","桃子"};
  18. request.setAttribute("n", n);
  19. request.setAttribute("arr", arr);
  20. %>
  21. <div style="width: 600px; margin: 0 auto; height: 800px">
  22. <h1> 循环遍历 </h1>
  23. <c:forEach begin="0" end="${n}" var="var" >
  24. ${var}
  25. </c:forEach>
  26. <h1> 循环数组 </h1>
  27. <ul>
  28. <c:forEach items="${arr}" var="var" >
  29. <li>${var}</li>
  30. </c:forEach>
  31. </ul>
  32. <h1> IF标签 </h1>
  33. <%
  34. //1 男生 2 女生
  35. int sex = 1;
  36. request.setAttribute("sex", sex);
  37. %>
  38. <c:if test="${sex == 1}" >
  39. <span>张三是男生</span>
  40. </c:if>
  41. <c:if test="${sex > 1}" >
  42. <span>张三是女生</span>
  43. </c:if>
  44. <h1> set标签 </h1>
  45. <c:set var="name" value="张三" scope="page" />
  46. <h5>${name}</h5>
  47. <h1> when标签 </h1>
  48. <c:choose>
  49. <c:when test="${sex == 1}"><span>张三是男生</span></c:when>
  50. <c:when test="${sex > 1}"><span>张三是女生</span></c:when>
  51. <c:otherwise><span>张三不明生物</span></c:otherwise>
  52. </c:choose>
  53. </div>
  54. </body>
  55. </html>