Latest web development tutorials

fonction startsWith (): JSTL fn

JSP standard Tag Library JSP standard Tag Library

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

grammaire

fn: () fonction syntaxe startsWith est la suivante:

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

Exemples Démo

Les exemples suivants démontrent les capacités 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="w3big: I am from w3big."/>
<c:if test="${fn:startsWith(string, 'Google')}">
   <p>字符串以 Google 开头</p>
</c:if>
<br />
<c:if test="${fn:startsWith(string, 'w3big')}">
   <p>字符串以 w3big 开头</p>
</c:if>

</body>
</html>

Les résultats sont les suivants:

字符串以 w3big 开头

JSP standard Tag Library JSP standard Tag Library