<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Test JSTL</title>
</head>
<body>
<!-- 赋值 -->
<c:set var="name" value="zhang" scope="request">
</c:set>
<!-- EL显示内容 -->
${requestScope.name }<br />
<!-- JSTL显示内容 -->
<c:out value="${requestScope.name}"></c:out> <br />
<!-- EL三元运算 -->
${empty(requestScope.name) ? 'name is null' : requestScope.name } <br />
<!-- JSTL输出控制 -->
<c:out value="${requestScope.name}" default="name is null"></c:out> <br />
<!-- JSTL if 语句 -->
<c:if test="${empty requestScope.name}" var="aa" scope="page">
not null <br />
</c:if>
<c:if test="${!aa}">
is null <br />
</c:if>
<!-- JSTL删除元素 -->
<c:remove var="name" scope="request"></c:remove>
<!-- JSTL多重分支 -->
<c:set var="money" value="5000" scope="request">
</c:set>
${requestScope.money }
<c:choose>
<c:when test="${money >= 1000}">
大于1000<br />
</c:when>
<c:when test="${money <= 1000 && money >=500}">
小于1000大于500<br/>
</c:when>
<c:otherwise>
其他情况<br/>
</c:otherwise>
</c:choose>
<!-- JSTL多重分支判断字符串 -->
<c:set var="uName" value="aaa" scope="request">
</c:set>
<c:choose>
<c:when test="${uName == 'lyq'}">
lyq<br/>
</c:when>
<c:when test="${uName eq 'aaa'}">
aaa
</c:when>
<c:otherwise>
不知道
</c:otherwise>
</c:choose>
<br/>
<!-- JSTL循环 -->
<c:forEach begin="1" end="10" varStatus="aaa">
${aaa.index } ++ ${aaa.count }<br/>
</c:forEach>
<br/>
<!-- JSTL循环遍历集合 -->
<table border="1">
<tr>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
</tr>
<c:forEach var="stu" items="${requestScope.list}">
<tr>
<td>${stu.name }</td>
<td>${stu.age }</td>
<td>${stu.sex }</td>
</tr>
</c:forEach>
</table>
</body>
</html>
JSTL核心实例
最新推荐文章于 2019-08-20 16:01:27 发布