Use of Tag of JSTL

In this section, you will learn how to use Tag of JSTL.

Use of Tag of JSTL

Use of <fn:startsWith(String, String)> Tag of JSTL

     

In this section we will learn how to use <fn:startssWith>  Tag of JSTL. This tag is used to check that given string starts with the specified sub string or not. This takes string type as arguments and return boolean type true or false.

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

startsWith_fnJstlTag.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
    <head>
        <title>Example of 'fn:startsWith' tag of jstl</title>
    </head>
    <body>
<form method="POST">
    Enter you lottery number that will process with today's lucky number<br>
        and show your winning status.
    <table bgcolor="">     
        <tr>
            <td>Enter lottery number</td>
            <td><input type="text" name="number"></td>
        </tr>
        
                <tr>
            <td></td>
            <td><input type="submit" value="check"></td>
        </tr>
    </table>  
</form>
<c:if test="${pageContext.request.method=='POST'}">    
    <c:set var="number" value="${param.number}"/>   
    <c:choose>

        <c:when test="${fn:startsWith(number, '23')==true}">

            <font size="5" color="green">Congratulations!
            You are the lucky winner.</font>
        </c:when>
        
                <c:otherwise>
            <font size="5" color="red">Sorry, number not matched.</font>
        </c:otherwise>
    </c:choose>
</c:if>
    </body>
</html>


This jsp code shows the following output :



Here user will enter the lottery number, if lottery number starts with digit '23', output will be.....


If found any error or number not matched, output will be.......



Download Source Code