Latest web development tutorials

JSTL fn: contém function ()

JSP Standard Tag Library JSP Standard Tag Library

fn: função contém () é usado para determinar se uma seqüência contém um substring especificado.

gramática

fn: () função contém a sintaxe é a seguinte:

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

Exemplos Demonstração

Os exemplos a seguir demonstram as capacidades desta função:

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

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

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

</body>
</html>

Os resultados são como se segue:

找到 w3big

JSP Standard Tag Library JSP Standard Tag Library