fn:contains() Function

JSP 标准标签库JSP Standard Tag Library

The fn:contains() function is used to determine whether a string contains a specified substring.

Syntax

The syntax of the fn:contains() function is as follows:

<c:if test="${fn:contains(<原始字符串>, <要查找的子字符串>)}">
...
</c:if>

Example

The following example demonstrates the functionality of this function:

<%@ 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 example"/>

<c:if test="${fn:contains(theString, 'example')}">
   <p>找到 example<p>
</c:if>

<c:if test="${fn:contains(theString, 'EXAMPLE')}">
   <p>找到 EXAMPLE<p>
</c:if>

</body>
</html>

The output is as follows:

找到 example

JSP 标准标签库JSP Standard Tag Library

Other Extensions