fn:contains()函數
fn:contains()函數用於確定一個字串是否包含指定的子串。
語法
fn:contains()函數的語法如下:
<c:if test="${fn:contains(<原始字串>, <要查找的子字串>)}">
...
</c:if>
實例演示
以下實例演示了這個函數的功能:
<%@ 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 函數</title>
</head>
<body>
<c:set var="theString" value="I am from zaixian"/>
<c:if test="${fn:contains(theString, 'zaixian')}">
<p>找到 zaixian<p>
</c:if>
<c:if test="${fn:contains(theString, 'zaixian')}">
<p>找到 zaixian<p>
</c:if>
</body>
</html>
運行結果如下:
找到 zaixian

JSP 標準標籤庫