12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
- <%--
- Created by IntelliJ IDEA.
- User: 武恒
- Date: 2023/2/18
- Time: 15:31
- To change this template use File | Settings | File Templates.
- --%>
- <%@ page contentType="text/html;charset=UTF-8" language="java" %>
- <html>
- <head>
- <title>JSTL 标签</title>
- </head>
- <body>
- <%
- int n = 10;
- String[] arr = {"苹果","鸭梨","香蕉","菠萝","桃子"};
- request.setAttribute("n", n);
- request.setAttribute("arr", arr);
- %>
- <div style="width: 600px; margin: 0 auto; height: 800px">
- <h1> 循环遍历 </h1>
- <c:forEach begin="0" end="${n}" var="var" >
- ${var}
- </c:forEach>
- <h1> 循环数组 </h1>
- <ul>
- <c:forEach items="${arr}" var="var" >
- <li>${var}</li>
- </c:forEach>
- </ul>
- <h1> IF标签 </h1>
- <%
- //1 男生 2 女生
- int sex = 1;
- request.setAttribute("sex", sex);
- %>
- <c:if test="${sex == 1}" >
- <span>张三是男生</span>
- </c:if>
- <c:if test="${sex > 1}" >
- <span>张三是女生</span>
- </c:if>
- <h1> set标签 </h1>
- <c:set var="name" value="张三" scope="page" />
- <h5>${name}</h5>
- <h1> when标签 </h1>
- <c:choose>
- <c:when test="${sex == 1}"><span>张三是男生</span></c:when>
- <c:when test="${sex > 1}"><span>张三是女生</span></c:when>
- <c:otherwise><span>张三不明生物</span></c:otherwise>
- </c:choose>
- </div>
- </body>
- </html>
|