Skip to content

Files

Latest commit

5142ebd · Oct 15, 2019

History

History
38 lines (28 loc) · 1.37 KB

18.md

File metadata and controls

38 lines (28 loc) · 1.37 KB

fn:contains() - JSTL 函数

原文: https://beginnersbook.com/2013/12/fncontains-jstl-function/

fn:contains()函数检查给定字符串是否作为子字符串存在于输入中。它执行区分大小写检查,这意味着它在检查子字符串时会考虑这种情况。

语法:

boolean fn:contains(String inputstring, String checkstring)

该函数的返回类型是boolean。当输入字符串中存在检查字符串时返回true,否则返回false。它有两个字符串参数 - 第一个有输入字符串,第二个参数有需要在输入字符串中检查的字符串。

fn:contains()的例子

在此示例中,我们检查新密码是否包含旧密码作为子字符串,如果是,则我们向用户显示消息。

<%@ 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>fn:contains example</title>
</head>
<body>
<c:set var="oldPassword" value="HelloPass"/>
<c:set var="newPassword" value="HelloPassNew" />
<c:if test="${fn:contains(newPassword, oldPassword)}">
 <c:out value="New Password should not contain old password as substring"/>
</c:if>
</body>
</html>

输出:

fn-contains-example