fn:startsWith() Function
The fn:startsWith() function is used to determine if a string starts with a specified prefix.
Syntax
The syntax of the fn:startsWith() function is as follows:
<c:if test="${fn:startsWith(<original string>, <search prefix>)}">
...
</c:if>
Example Demonstration
The following example demonstrates the functionality of this function:
<%@ 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>Using JSTL Functions</title>
</head>
<body>
<c:set var="string" value="tutorialpro: I am from tutorialpro."/>
<c:if test="${fn:startsWith(string, 'Google')}">
<p>The string starts with Google</p>
</c:if>
<br />
<c:if test="${fn:startsWith(string, 'tutorialpro')}">
<p>The string starts with tutorialpro</p>
</c:if>
</body>
</html>
The output is as follows:
The string starts with tutorialpro