jstl:
if语句
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>if 标签</title>
</head>
<body>
<%-- if 标签
格式
<c:if text="<boolean>" var="<String>" scope="<String>">
....
</c:if>
--%>
<%
request.setAttribute("num",10);
%>
<c:if test="${num}">
数值大于0
</c:if>
<c:if test="${num > 100}" var="flag" scope="request"></c:if>
${flag} -- ${request.flag}
</body>
</html>
forEach语句
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>forEach</title>
</head>
<body>
<%-- 相当于for(int i = 0; i<10; i++)--%>
<c:forEach var="i" begin="1" end="10" step="2">
${i}
</c:forEach>
<%
List<String> list = new ArrayList<>();
for (int i = 0; i<10;i++){
list.add("A:" + i);
}
pageContext.setAttribute("li",list);
// 相当于:
// for (String li : list){
// out.print(li);
// }
%>
<c:forEach items="${li}" var="item">
${item}
</c:forEach>
<table align="center" width="800" border="1" style="border-collapse: collapse">
<tr>
<th>名称</th>
<th>当前成员的下标</th>
<th>当前成员的循环数</th>
<th>是否第一次被循环</th>
<th>是否最后一次循环</th>
</tr>
<c:forEach items="${li}" var="item" varStatus="itemp">
<tr>
<td>${item}</td>
<td>${item}</td>
<td>${item}</td>
<td>${item}</td>
<td>${item}</td>
</tr>
</c:forEach>
</table>
<%
List<User> userList = new ArrayList<>();
for (int i = 0;i<3;i++){
User user1 = new User(1,"gagu","duygauhi");
userList.add(user1);
request.setAttribute("userList",userList);
}
%>
<c:if test="${!empty userList}">
<table align="center" width="800" border="1" style="border-collapse: collapse">
<tr>
<th>用户编号</th>
<th>用户名称</th>
<th>用户密码</th>
<th>用户操作</th>
</tr>
<c:forEach items="${userList}" var="user">
<tr>
<td>${user.userId}</td>
<td>${user.uname}</td>
<td>${user.upwd}</td>
<td><button>修改</button></td>
</tr>
</c:forEach>
</c:if>
</body>
</html>
choose when otherwise语句
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>choose when otherwise</title>
</head>
<body>
<%
request.setAttribute("score",80);
%>
<c:choose>
<c:when test="${score <60}">
你个渣渣
</c:when>
<c:when test="${score>=60 && score<=80}">
可以可以
</c:when>
<c:otherwise>
牛逼
</c:otherwise>
</c:choose>
</body>
</html>