Home Jsp Use of Tag of JSTL
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Use of Tag of JSTL

Advertisement
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)

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

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 24, 2008

Ask Questions?    Discuss: Use of Tag of JSTL  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com