JSTL 是由 JSP 所指定的标准规范,主要提供给 JavaWeb 开发人员一个标准通用的标签函数库
标签库分类:
1、核心标签库(常用)
2、I18N 格式标签库(国际化使用)
3、SQL 标签库
4、XML 标签库
5、函数标签库
功能分类:
1、表达式操作
标签名称:out、set、remove
2、流程控制
标签名称:if、choose、when、otherwise
3、迭代操作
标签名称:forEach、fotTokens
4、URL 操作
标签名称:Import、param、url、redirect
使用:
1、表达式操作
首先在 JSP 页面头部引入函数声明

使用 < c : out > 输出内容

该函数可以对特殊字符进行转换
使用 < c : set > 赋值
1、

在 request 范围内,给 name 属性赋值为 test,同时支持 EL 表达式
2、

由图,给 JavaBean 赋值,target 指定目标的实体,property 指定属性名,value 为属性值
使用 < c : remove > 移除指定域对象的指定属性

2、流程控制
1、< c : if > 使用:

该用法没有 else,但是可以保存在指定范围内,以便后面使用:

2、< c : choose,c : when,c : otherwise >
该用法可以实现 if ... else 效果

其中,c:choose 以 c:when,c:otherwise 的父标签出现,c:when,c:otherwise 不能脱离 c:choose 单独使用,c:otherwise 必须在 c:when 之后使用。
3、迭代操作
<c : foreach> 可以对数组,Collection,Map 进行遍历
属性:
1、var:用来存放现在指定的成员
2、items:被迭代的集合对象
3、varStatus:用来存放现在指定的相关成员信息
4、begin:开始的位置
5、end:结束的位置
6、step:每次迭代的间隔数
使用:
1、循环遍历集合

运行结果:

输出指定位置到指定位置

从索引位置为 2 开始,到索引为 6 结束,间隔为 2 输出结果:

2、循环遍历map

运行结果:

3、循环遍历数组

运行结果:

以上为本人的一些学习笔记,如有出错欢迎指正,陆续更新!!!
网友评论