一。C 标签库:
1.引入标签:<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
2.
<c:out> | 用于计算一个表达式并将结果输出。类似于 JSP 中 <%=%> 表达式 | |
<c:set> | 用于设置范围变量的值或者 javabean 对象的属性 | <c:set var=”username” value=”lisi” scope=”session”/>
|
<c:remove> | 相对 <c:set> 其作用是移除范围变量 | <c:remove var=”nusername” scope=”session”/> |
<c:catch> | 用于捕获在其中嵌套的操作所抛出的异常对象,并将异常信息保存到变量中。 | <c:catch var=”exception”><%int i = 5; int j = 0; int k=i/j;%></c:catch> |
<c:if> | 用于实现 java 中的 if 语句功能 | <c:if test=”${user.visitCount==1}”> This is your first visit . </c:if> |
<c:choose> | <c:choose> 和 <c:when> 、 <c:otherwise> 一起实现互斥条件执行 | <c:choose> <c:when test="${row.v_money<10000}"> 初学下海 </c:when> <c:when test="${row.v_money>=10000&&row.v_money<20000}"> 身手小试 </c:when> <c:otherwise> 商业能手 </c:otherwise> </c:choose> |
<c:forEach> | 遍历记录集 | 1.<c:forEach var =”i” begin=”100 “ end= “110”> ${i} </c:forEach> 2. <c:forEach var="vo" items="${companys}"> <tr> <td>${ vo.id }</td> <td>${ vo.name }</td> </tr> </c:forEach> |
|
|
|
二。Functions 标签库: 可以对集合或者字符串的一些方法调用或者说同样的效果
1.引入标签<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
2.方法解析
函数 | 描述 |
fn:contains(string, substring) | 如果参数string中包含参数substring,返回true |
fn:containsIgnoreCase(string, substring) | 如果参数string中包含参数substring(忽略大小写),返回true |
fn:endsWith(string, suffix) | 如果参数 string 以参数suffix结尾,返回true |
fn:escapeXml(string) | 将有特殊意义的XML (和HTML)转换为对应的XML character entity code,并返回 |
fn:indexOf(string, substring) | 返回参数substring在参数string中第一次出现的位置 |
fn:join(array, separator) | 将一个给定的数组array用给定的间隔符separator串在一起,组成一个新的字符串并返回。 |
fn:length(item) | 返回参数item中包含元素的数量。参数Item类型是数组、collection或者String。如果是String类型,返回值是String中的字符数。 |
fn:replace(string, before, after) | 返回一个String对象。用参数after字符串替换参数string中所有出现参数before字符串的地方,并返回替换后的结果 |
fn:split(string, separator) | 返回一个数组,以参数separator 为分割符分割参数string,分割后的每一部分就是数组的一个元素 |
fn:startsWith(string, prefix) | 如果参数string以参数prefix开头,返回true |
fn:substring(string, begin, end) | 返回参数string部分字符串, 从参数begin开始到参数end位置,包括end位置的字符 |
fn:substringAfter(string, substring) | 返回参数substring在参数string中后面的那一部分字符串 |
fn:substringBefore(string, substring) | 返回参数substring在参数string中前面的那一部分字符串 |
fn:toLowerCase(string) | 将参数string所有的字符变为小写,并将其返回 |
fn:toUpperCase(string) | 将参数string所有的字符变为大写,并将其返回 |
fn:trim(string) | 去除参数string 首尾的空格,并将其返回 |
3.实例应用 注意,其应用是在el表达是中的
截图:
函数名 | 函数说明 | 使用举例 |
fn:contains | 判断字符串是否包含另外一个字符串 | <c:if test="${fn:contains(name, searchString)}"> |
fn:containsIgnoreCase | 判断字符串是否包含另外一个字符串(大小写无关) | <c:if test="${fn:containsIgnoreCase(name, searchString)}"> |
fn:endsWith | 判断字符串是否以另外字符串结束 | <c:if test="${fn:endsWith(filename, ".txt")}"> |
fn:escapeXml | 把一些字符转成XML表示,例如<字符应该转为< | ${fn:escapeXml(param:info)} |
fn:indexOf | 子字符串在母字符串中出现的位置 | ${fn:indexOf(name, "-")} |
fn:join | 将数组中的数据联合成一个新字符串,并使用指定字符格开 | ${fn:join(array, ";")} |
fn:length | 获取字符串的长度,或者数组的大小 | ${fn:length(shoppingCart.products)} |
fn:replace | 替换字符串中指定的字符 | ${fn:replace(text, "-", "•")} |
fn:split | 把字符串按照指定字符切分 | ${fn:split(customerNames, ";")} |
fn:startsWith | 判断字符串是否以某个子串开始 | <c:if test="${fn:startsWith(product.id, "100-")}"> |
fn:substring | 获取子串 | ${fn:substring(zip, 6, -1)} |
fn:substringAfter | 获取从某个字符所在位置开始的子串 | ${fn:substringAfter(zip, "-")} |
fn:substringBefore | 获取从开始到某个字符所在位置的子串 | ${fn:substringBefore(zip, "-")} |
fn:toLowerCase | 转为小写 | ${fn.toLowerCase(product.name)} |
fn:toUpperCase | 转为大写字符 | ${fn.UpperCase(product.name)} |
fn:trim | 去除字符串前后的空格 | ${fn.trim(name)} |
三。格式化标签
1.引入标签:<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
2.方法解释
1),格式化日期
Value:表示的是日期
Type:表示的是日期显示的格式,date表示显示时间,time表示显示日期,both表示时间和日期都显示
pattern:以某种模式显示时间
var:表示将时间放到某个变量中
- <fmt:formatDate value=”${today}” type=”date”></fmt:formatDate>
- <fmt:formatDate value=”${today}” type=”time”></fmt:formatDate>
- <fmt:formatDate value=”${today}” type=”both”></fmt:formatDate>
- <fmt:formatDate value=”${today}” pattern=”yyyy-MM-dd HH:mm:ss” var=”d”></fmt:formatDate>
2),格式化数字
value:表示的是数字
pattern:表示格式的模式
groupingUsed:表示的是数字是否分组,默认true表示分组,false表示不分组
maxIntegerDigits:整数位最长多少位
minIntegerDigits:整数位最短多少位
maxFractionDigits:小数位最大多少位
minFractionDigits:小数位最少多少位
type:表示类型,其值currency表示货币,percent表示百分比
currencySymbol:表示货币符号
var:表示存储数字的变量
<fmt:formatNumber value=”${n}” pattern=”###,###,###” groupingUsed=”false”/><p><fmt: formatNumber value =”12.3” pattern=”.000”/></p>