fn:endsWith()函數(shù)用于確定一個字符串是否以指定后綴結(jié)尾。
fn:endsWith()函數(shù)的語法如下:
<c:if test="${fn:endsWith(<原始字符串>, <要查找的子字符串>)}">
...
</c:if>以下示例演示了這個函數(shù)的功能:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<html>
<head>
<title>使用 JSTL 函數(shù)</title>
</head>
<body>
<c:set var="theString" value="I am from nhooo 123"/>
<c:if test="${fn:endsWith(theString, '123')}">
<p>字符串以 123 結(jié)尾<p>
</c:if>
<c:if test="${fn:endsWith(theString, 'hooo')}">
<p>字符串以 nhooo 結(jié)尾<p>
</c:if>
</body>
</html>運(yùn)行結(jié)果如下:
字符串以 123 結(jié)尾