<%@ page language="java" import="java.util.*, cn.hncu.domain.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<p> c:forEach标签 </p>
一、普通for循环的功能
<c:forEach begin="1" end="10" var="i" step="2">
${i}<br/>
</c:forEach>
二、增强for循环的功能<br/>
1.遍历数组<br/>
<%
String strs[] = {"aa","bb","cc"};
pageContext.setAttribute("strs", strs);
%>
<c:forEach items="${strs}" var="str">
${str},
</c:forEach>
<br/>
2.遍历List<br/>
<%
List list = new ArrayList();
list.add("aaa");
list.add("bbb");
list.add("ccc");
pageContext.setAttribute("list", list);
%>
<c:forEach items="${list}" var="a">
${a},
</c:forEach>
<br/>
3.遍历Map<br/>
<%
Map map = new HashMap();
map.put("name", "李四");
map.put("age",24);
map.put("addr","安置小区");
pageContext.setAttribute("map", map);
%>
<c:forEach items="${map}" var="aa">
${aa} ==> ${aa.key} , ${aa.value} <br/>
</c:forEach>
<br/>
3.遍历元素为值对象的集合,如List<User> <br/>
<%
List<User> list2 = new ArrayList<User>();
list2.add( new User("Mike","1234",20));
list2.add( new User("Mike2","1234",22));
list2.add( new User("Mike3","4322",21));
list2.add( new User("Rose","111",10));
pageContext.setAttribute("list2", list2);
%>
<c:forEach items="${list2}" var="user" varStatus="idx">
<!--index为下标的序号(索引), count为记数 -->
${idx.index},${idx.count}:
<c:out value="${user.name}"></c:out> ,
<c:out value="${user.pwd}"></c:out> ,
<c:out value="${user.age}"></c:out> <br/>
</c:forEach>
<hr/>
<p> c:choose,when,otherwise标签 </p>
<c:set var="score" value="65" scope="session"></c:set>
<c:choose>
<c:when test="${score>=90}">
优秀
</c:when>
<c:when test="${score>=80}">
良好
</c:when>
<c:when test="${score>=70}">
中等
</c:when>
<c:otherwise>
毕不了业
</c:otherwise>
</c:choose>
<p> forTokens标签 </p>
<c:forTokens items="a,b,c,d,23,tt" delims="," var="x">
${x} <br/><!-- 这里是把字符串按逗号分隔开来,相当于String中的split方法 -->
</c:forTokens>
<p> url相关的标签: url,import,redirect </p>
<!-- 重写url技术,路径中的斜杠就是项目根目录 -->
<a href="<c:url value='/ShowServlet' />">显示所有用户信息</a> <br/>
<!-- 动态包含 -->
<c:import url="/jsps/foot.jsp"></c:import>
<%--小心,页面中写了c:redirect,就会立即重定向到其它页面。不会再停留在当前页面
<c:redirect url="/jsps/show.jsp"></c:redirect>
response.sendRedirect("/jsps/show.jsp");
--%>
<p> c:remove标签:移除属性变量, 和set是相反 </p>
<c:remove var="score"/>
score: ${score}
</body>
</html>