set标签可以往域中保存数据
scope 设置保存到哪个域
var 属性值的key
value 属性的值
<c:set scope="request" var="key1" value="cuijintao"/>
${requestScope.key1}<br/>
if标签用来做if判断
test属性表示判断的条件 (条件表达式用el表达式输出)
<c:if test="${12 > 1}">
我是个好人<br/>
</c:if>
<c:choose> <c:when> <c:otherwise>标签
类似于switch ... case ... default
choose 开始选择判断
when 表示每一种判断情况
test 属性表示当前这种判断情况的值
otherwise 标签表示剩下的情况
<c:choose> <c:when> <c:otherwise>标签使用需要注意的点:
1.标签里不能有html注释,要使用jsp注释.
2.when标签的父标签一定是 choose标签
<%
request.setAttribute("grade",89);
%>
<c:choose>
<c:when test="${requestScope.grade>=90}">
<h4>成绩优秀</h4>
</c:when>
<c:when test="${requestScope.grade>=80}">
<h4>成绩良好</h4>
</c:when>
<c:when test="${requestScope.grafe>=70}">
<h4>成绩及格</h4>
</c:when>
<c:otherwise>
<h4>成绩不合格</h4>
</c:otherwise>
</c:choose>
forEach 标签 用来遍历输出
begin 开始的索引
end 结束的索引
var 属性表示循环的变量(也是当前遍历到的数据)
items 表示遍历的集合
step 遍历的步长值 默认为1
varStatus 表示当前遍历到的数据的状态
<%-- 1.遍历输出1到10 --%>
<c:forEach begin="1" end="10" var="i">
${i}<br/>
</c:forEach>
<hr/>
<%-- 2.遍历对象数组 --%>
<%
request.setAttribute("arr",new String[]{"110","120","119"});
%>
<c:forEach items="${requestScope.arr}" var="i">
${i}<br/>
</c:forEach>
<%-- 3.遍历map --%>
<%
Map<String,Object> map=new HashMap<String, Object>();
map.put("key1","value1");
map.put("key2","value2");
map.put("key3","value3");
request.setAttribute("map",map);
%>
<c:forEach items="${requestScope.map}" var="i">
${i.key} = ${i.value}
</c:forEach>
<%-- 4.遍历list集合 --%>
<%
List<Student> studentList=new ArrayList<Student>();
for (int i = 0; i < 10 ; i++) {
studentList.add(new Student(0+i,"username"+i,"password"+i,18+i,"phone"+i));
}
request.setAttribute("students",studentList);
%>
<table border="1" align="center" cellpadding="0" cellspacing="0">
<c:forEach items="${requestScope.students}" var="student">
<tr>
<td>${student.id}</td>
<td>${student.username}</td>
<td>${student.password}</td>
<td>${student.age}</td>
<td>${student.phone}</td>
</tr>
</c:forEach>
</table>
版权声明:本文为m0_64819482原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。