下面只介绍if和foreach两个案例
主要和EL来取代传统页面上直接嵌入Java代码写法。提升程序可读性、维护性和方便性。
1.0不支持EL表达式
1.1 1.2支持EL表达式
jstl.jar和standard.jar

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>这里uri只是引用jar包的内容,并不是真的要去sun.com去获取数据
<c:set value="bbb" var="name" scope="page"></c:set>
${name }
输出bbb只有if没有else,如果有其他条件就再来一遍
<c:set var="i" value="10" scope="page"></c:set>
<c:if test="${i>=10 }" var="flag" scope="page">
<span style="color:red;">i大于等于10</span>
</c:if>
<c:if test="${!flag }">
<span style="color:red;">i小于10</span>
</c:if>i大于等于10<body>
<h1>JSTLd的foreach标签的使用</h1>
<h2>遍历数组</h2>
<%
String[] arrs = {"aa","bb","cc"};
pageContext.setAttribute("arrs", arrs);
%>
<c:forEach var="s" items="${arrs }">
${s }
</c:forEach>
<h2>遍历List集合</h2>
<%
List<String> list = new ArrayList<String>();
list.add("11");
list.add("22");
list.add("33");
pageContext.setAttribute("list", list);
%>
<c:forEach var="l" items="${list }">
${l }
</c:forEach>
<h2>遍历Map集合</h2>
<%
Map<String,Integer> map = new HashMap<String,Integer>();
map.put("aaa", 111);
map.put("bbb", 222);
map.put("ccc", 333);
pageContext.setAttribute("map", map);
%>
<c:forEach var="m" items="${map }">
${m.key }-${m.value } <br>
</c:forEach>
<h2>遍历从1到10</h2>
<c:forEach var="i" begin="1" end="10" step="1">
${i }
</c:forEach>
<h2>遍历100到200 每次加2 到第三个数的时候将该数字变为蓝色</h2>
<c:forEach var="i" begin="100" end="200" step="2" varStatus="status">
<c:if var="flag" test="${status.count % 3 == 0 }">
<font color="red"> ${i }</font>
</c:if>
<c:if test="${!flag}">
<font> ${i }</font>
</c:if>
</c:forEach>
</body>