Fonction fn:startsWith()

JSP 标准标签库Bibliothèque de balises standard JSP

La fonction fn:startsWith() est utilisée pour déterminer si une chaîne commence par un préfixe spécifié.

Syntaxe

La syntaxe de la fonction fn:startsWith() est la suivante :

<c:if test="${fn:startsWith(<原始字符串>, <搜索的前缀>)}">
            ...
</c:if>

Exemple

L'exemple suivant montre le fonctionnement de cette fonction :

<%@ 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="string" value="Example: I am from Example."/>
<c:if test="${fn:startsWith(string, 'Google')}">
   <p>字符串以 Google 开头</p>
</c:if>
<br />
<c:if test="${fn:startsWith(string, 'Example')}">
   <p>字符串以 Example 开头</p>
</c:if>

</body>
</html>

La sortie est la suivante :

字符串以 Example 开头

JSP 标准标签库Bibliothèque de balises standard JSP

Autres extensions