JSTL Functions - startsWith()

The fn:startsWith() function determines whether an input string starts with a specified substring.

Syntax:

The fn:startsWith() function has following syntax:

boolean startsWith(java.lang.String, java.lang.String)

JSTL Example :

<%@ 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 Tutorial</title>
</head>
<body>
<c:set var="string" value="https://www.c4learn.com/"/>
<c:if test="${fn:startsWith(string, 'http')}">
   <p>HTTP Protocol</p>
</c:if>
<c:if test="${fn:startsWith(string, 'https')}">
   <p>HTTPS Protocol</p>
</c:if>
</body>
</html>

Output :

HTTP Protocol