12.25 补充总结-jsp标签

注:标签引用时,需在jsp 头部添加如下语句

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

1、jsp-jstl-if 标签的引用

if标签
格式:
<c:if test="${1==1}">
Hello
</c:if>
常用属性:
test:条件判断,操作的是域对象,接收返回结果是boolean类型的值(必要属性)
var:限域变量名(存放在作用域中的变量名),用于接受判断结果的值 (可选属性)
scope:限域变量名的范围(page,request,session,application)
注意事项:
1、标签操作一般都是域对象
2、if标签没有else 如果需要,则需要设置完全相反的条件判断语句

<c:if test="${1==1}">
    Hello
</c:if>

2、jsp-jstl choose otherwise when

JSTL中的choose when otherwise标签的使用
注:
1、choose标签没有属性
2、when标签只有一个test属性,必要的属性
注意:
1、choose标签和otherwise标签没有属性,而when标签必须有一个test属性
2、choose标签中必须包含至少一个when标签,可以没有otherwise标签
3、otherwise标签必须设置在最后一个when标签之后
4、choose标签中智能设置when标签与otherwise标签
5、when标签otherwise标签中可以嵌套其他标签
6、otherwise标签会在所有的when标签不执行时才会执行
<%
    request.setAttribute("score",999);
%>
<c:choose>
    <c:when test="${score<60}">
        成绩不合格
    </c:when>
    <c:when test="${score==60}">
        成绩及格
    </c:when>
    <c:when test="${score>60&&score<80}">
        成绩良好
    </c:when>
    <c:when test="${score>=80&&score<100}">
        成绩优秀
    </c:when>
    <c:otherwise>
        成绩输入错误!!
    </c:otherwise>
</c:choose>

3、jsp-jstl-foreach 标签的引用

foreach:当前这次迭代从0开始的迭代索引
count:当前这次迭代从1开始的的迭代计数
first:用来表名带你给钱这轮迭代是否为第一次迭代的标志
last:用来表名当前这轮迭代是否为最后一次迭代的标志
<c:forEach items="<object>" begin="<int>" end="<int>" step="<int>"
var="<string>"
varStatus="<string>"
></c:forEach>
1、迭代主题内容多次
<c:forEach items="<迭代主体>" begin="<开始数>" end="<结束数>" step="<间隔数>"
var="<限域变量名>"
varStatus="<属性>"
></c:forEach>
相当于Java中的 for。。。int 循环
for(int i=0;i<10;i++){}
2、循环
<c:forEach items="<要被循环的数据>"
var="<限域变量名>"
></c:forEach>

 

<c:forEach var="i" begin="1" end="10" step="2">
    ${i}<br>
</c:forEach>
<table align="center" width="600" 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>${itemp.index}</td>
            <td>${itemp.count}</td>
            <td>${itemp.first}</td>
            <td>${itemp.last}</td>
        </tr>
    </c:forEach>
</table>
posted @ 2022-01-01 09:06  往心。  阅读(45)  评论(0编辑  收藏  举报