fn:startsWith() JSTL Function

fn:startsWith() JSTL Function Example explains about if a specified input string starts with the specified prefix.

Consider an example where you need to check whether a string starts with a specified prefix.

fn:startsWith() JSTL Function will test if a specified input string starts with the specified prefix.

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

You can see the below example, which is demonstrating fn:startsWith() JSTL Function

Required Libraries

You need to download

  1. Tomcat 7
  2. JSTL 1.2

Following jar must be in classpath

  1. jstl-1.2.jar

fn:startsWith() 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 fn:startsWith</title>
</head>

<body>

    <%
        // you can also set the values into request scope same as using c:set
        // request.setAttribute("str", "This is a TEST String");
    %>
    <c:set var="str" value="This is a TEST String" />
    
    <c:if test="${fn:startsWith(str, 'This')}">
           <p>String starts with 'This'</p>
    </c:if>

</body>
</html>
Output
String starts with 'This'

 






Your email address will not be published. Required fields are marked *