Use of Tag of JSTL

In this section, you will learn how to use 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)


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

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

            <font size="5" color="green">Congratulations!
            You are the lucky winner.</font>
            <font size="5" color="red">Sorry, number not matched.</font>

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

Share on Google+Share on Google+

Use of Tag of JSTL

Posted on: August 24, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Use of Tag of JSTL  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image