JSTL核心标签

本文详细介绍了JSTL(JSP Standard Tag Library)中的内置函数,包括如何在JSP页面中引入JSTL库,以及如何使用如empty、contains、indexOf等函数进行条件判断和字符串操作。同时,还介绍了循环函数forEach的用法以及选择函数choose的使用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在使用JSTL前必须在JSP中引入标准函数的声明
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

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

下面是JSTL中自带的方法列表以及其描述

<c:if  test = ${}></c:if>

empty    not empty        判断属否为空                            <c:if test="${not empty fn}">
contains             判断字符串是否包含另外一个字符串                 <c:if test="${fn:contains(name, searchString)}">
containsIgnoreCase       判断字符串是否包含另外一个字符串(大小写无关)       <c:if test="${fn:containsIgnoreCase(name, searchString)}">
endsWith             判断字符串是否以另外字符串结束                 <c:if test="${fn:endsWith(filename, ".txt")}"> 

startsWith             判断字符串是否以某个子串开始                     <c:if test="${fn:startsWith(product.id, "100-")}">

${fn:}功能函数

escapeXml             把一些字符转成XML表示,例如<字符应该转为<             ${fn:escapeXml(param:info)}
indexOf             子字符串在母字符串中出现的位置                 ${fn:indexOf(name, "-")}
join                 将数组中的数据联合成一个新字符串,并使用指定字符格开     ${fn:join(array, ";")}
length                 获取字符串的长度,或者数组的大小             ${fn:length(shoppingCart.products)}
replace             替换字符串中指定的字符                     ${fn:replace(text, "-", "?")}
split                 把字符串按照指定字符切分                     ${fn:split(customerNames, ";")} 

substring             获取子串                             ${fn:substring(zip, 6, -1)}
substringAfter             获取从某个字符所在位置开始的子串            ${fn:substringAfter(zip, "-")}
substringBefore         获取从开始到某个字符所在位置的子串                 ${fn:substringBefore(zip, "-")}
toLowerCase            转为小写                             ${fn.toLowerCase(product.name)}
toUpperCase             转为大写字符                             ${fn.UpperCase(product.name)}
trim                 去除字符串前后的空格                         ${fn.trim(name)} 

 

循环函数

forEach                循环打印对象                        <c:forEach items="${fn}" var="li">

例如:

<c:forEach items="${fn}" var="li" varStatus="index"  >

${index.index} 个 元素 是${li.name }  //name 是指li对象里面字段  需有get方法

</c:forEach>

选择函数:

choose                根据bean选择                            </c:choose><c:when test="${page.num != 1}"></c:when><c:otherwise></c:otherwise></c:choose>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值