Latest web development tutorials

JSTL의 FN : startsWith () 함수

JSP 표준 태그 라이브러리 JSP 표준 태그 라이브러리

FN : startsWith () 함수는 캐릭터 라인이, 지정된 접두사로 시작 여부를 확인하는 데 사용됩니다.

문법

FN 다음과 같이 () 구문 startsWith 기능은 다음과 같습니다

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

결과는 다음과 같습니다 :

字符串以 w3big 开头

JSP 표준 태그 라이브러리 JSP 표준 태그 라이브러리