中国最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2

JSP教程

JSTL fn:contains()函数

阅读 (2070)

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 w3cschool"/>

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

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

</body>
</html>

运行结果如下:

找到 w3cschool
关闭
程序员人生