Jar包

前台

完整代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.*,bean.*"%>
<br>
-- 加入jstl中心 --
<br>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<%
		request.setAttribute("name", "Davis");
	%>
	${name }
	<br>

	<br>-- cout,输出标签 --
	<br>
	<c:out value="${name }"></c:out>

	<br>-- ccatch捕获异常标签 --
	<br>
	<c:catch var="e">
${pageContext.name }<br>
	</c:catch>
	<br>${e.message }<br>

	<br>-- cif判断标签 --
	<br>
	<c:if test="${name=='Davis' }">
	Hello Davis!<br>
	</c:if>

	<br>-- cchoose多项选择标签 --
	<br>
	<%
		pageContext.setAttribute("hobby", "ball");
	%>
	<c:choose>
		<c:when test="${hobby=='basketball'}">
			<br>
	I like play basketball!
</c:when>
		<c:when test="${hobby=='football' }">
	I like play football!
</c:when>
		<c:when test="${hobby=='volleyball' }">
I like play volleyball!
</c:when>
		<c:otherwise>
I don't have any hobbies!<br>
		</c:otherwise>
	</c:choose>
	<br>-- cforeach遍历数组标签 --
	<br>
	<%
		Object[] animal = { "青蛙", "蜻蜓", "蜘蛛", "蝴蝶" };
		pageContext.setAttribute("animal", animal);
	%>
	<br>
	<c:forEach items="${animal }" var="q">
	${q }<br>
	</c:forEach>

	<br>-- cforeach遍历list标签 --
	<br>
	<%
		List<String> list = new ArrayList<>();
		list.add("上海");
		list.add("长沙");
		list.add("炎陵");
		pageContext.setAttribute("city", list);
	%>
	<c:forEach items="${city }" var="d">
	${d }<br>
	</c:forEach>

	<br>-- 遍历Set --
	<br>

	<br>-- 遍历map key:value--
	<br>
	<%
		Map<String, String> map = new HashMap<>();
		map.put("1", "Davis");
		map.put("2", "Linda");
		map.put("3", "Jack");
		pageContext.setAttribute("rank", map);
	%>
	<c:forEach items="${rank }" var="name">
  	${name.key}:${name.value }<br>
	</c:forEach>

	<br>--遍历起始索引及步长 (1)begin end --
	<br>
	<%
		Object[] country = { "0 China", "1 America", "2 Germany", "3 Franch", "4 Britain", "5 Italy" };
		pageContext.setAttribute("country", country);
	%>
	<c:forEach items="${country }" var="c" begin="0" end="5">
	
	${c }<br>

	</c:forEach>
	<br>--遍历起始索引及步长 (2)step --
	<br>
	<c:forEach items="${country }" var="c" begin="0" end="5" step="2">
	${c }<br>
	</c:forEach>
	<br>--varStatus --
	<br>
	<%
		List<Strudent> staffs = new ArrayList<>();
		staffs.add(new Strudent("刘三", 20));
		staffs.add(new Strudent("王石", 21));
		staffs.add(new Strudent("李八", 22));
		staffs.add(new Strudent("孙事", 23));
		staffs.add(new Strudent("郭明", 24));
		staffs.add(new Strudent("张书", 25));
		pageContext.setAttribute("Staffs", staffs);
	%>
	<table>
		<tr Style="background-color: blue">
			<td>序号</td>
			<td>名字</td>
			<td>年龄</td>
		</tr>
		<c:forEach items="${Staffs }" var="sta" varStatus="vs">
			<tr Style="background-color:${vs.index % 2 ==0?'orange':'gray'}">
				<td>${vs.count }</td>
				<td>${sta.name }</td>
				<td>${sta.age }</td>
			</tr>
		</c:forEach>
	</table>
</body>
</html>

加入jstl中心

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

cout,输出标签

	<%
		request.setAttribute("name", "Davis");
	%>
	${name }
	<br>
	<br>
	<c:out value="${name }"></c:out>

ccatch捕获异常标签

	<br>
	<c:catch var="e">
${pageContext.name }<br>
	</c:catch>
	<br>${e.message }<br>

	<br>-- cif判断标签 --
	<br>
	<c:if test="${name=='Davis' }">
	Hello Davis!<br>
	</c:if>

cchoose多项选择标签

	<br>
	<%
		pageContext.setAttribute("hobby", "ball");
	%>
	<c:choose>
		<c:when test="${hobby=='basketball'}">
			<br>
	I like play basketball!
</c:when>
		<c:when test="${hobby=='football' }">
	I like play football!
</c:when>
		<c:when test="${hobby=='volleyball' }">
I like play volleyball!
</c:when>
		<c:otherwise>
I don't have any hobbies!<br>
		</c:otherwise>
	</c:choose>

cforeach遍历数组标签

	<br>
	<%
		Object[] animal = { "青蛙", "蜻蜓", "蜘蛛", "蝴蝶" };
		pageContext.setAttribute("animal", animal);
	%>
	<br>
	<c:forEach items="${animal }" var="q">
	${q }<br>
	</c:forEach>

cforeach遍历list标签

	<br>
	<%
		List<String> list = new ArrayList<>();
		list.add("上海");
		list.add("长沙");
		list.add("炎陵");
		pageContext.setAttribute("city", list);
	%>
	<c:forEach items="${city }" var="d">
	${d }<br>
	</c:forEach>

遍历map key:value

	<br>
	<%
		Map<String, String> map = new HashMap<>();
		map.put("1", "Davis");
		map.put("2", "Linda");
		map.put("3", "Jack");
		pageContext.setAttribute("rank", map);
	%>
	<c:forEach items="${rank }" var="name">
  	${name.key}:${name.value }<br>
	</c:forEach>

遍历起始索引及步长 (1)begin end

	<br>
	<%
		Object[] country = { "0 China", "1 America", "2 Germany", "3 Franch", "4 Britain", "5 Italy" };
		pageContext.setAttribute("country", country);
	%>
	<c:forEach items="${country }" var="c" begin="0" end="5">
	
	${c }<br>

	</c:forEach>

遍历起始索引及步长 (2)step

	<br>
	<c:forEach items="${country }" var="c" begin="0" end="5" step="2">
	${c }<br>
	</c:forEach>
	<br>--varStatus --
	<br>
	<%
		List<Strudent> staffs = new ArrayList<>();
		staffs.add(new Strudent("刘三", 20));
		staffs.add(new Strudent("王石", 21));
		staffs.add(new Strudent("李八", 22));
		staffs.add(new Strudent("孙事", 23));
		staffs.add(new Strudent("郭明", 24));
		staffs.add(new Strudent("张书", 25));
		pageContext.setAttribute("Staffs", staffs);
	%>
	<table>
		<tr Style="background-color: blue">
			<td>序号</td>
			<td>名字</td>
			<td>年龄</td>
		</tr>
		<c:forEach items="${Staffs }" var="sta" varStatus="vs">
			<tr Style="background-color:${vs.index % 2 ==0?'orange':'gray'}">
				<td>${vs.count }</td>
				<td>${sta.name }</td>
				<td>${sta.age }</td>
			</tr>
		</c:forEach>
	</table>