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 Tag of JSTL.

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

     

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

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

endsWith_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:endsWith' tag of jstl</title>
    </head>
    <body>
        <form method="POST">
            Here only .txt, .doc, .pdf are allowed.This application will check 
            <br>that you have entered file with valid extension or not.
            <table bgcolor="">     
                <tr>
                    <td>Enter file name with extension</td>
                    <td><input type="text" name="fName"></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="fname" value="${param.fName}"/>   
            <c:choose>

                <c:when test="${fn:endsWith(fname, '.txt')==true}">

                    <font size="5" color="green">Given file is text file.</font>
                </c:when>
                
                                <c:when test="${fn:endsWith(fname, '.doc')==true}">

                    <font size="5" color="green">Given file is document file.</font>
                </c:when>
                
                                <c:when test="${fn:endsWith(fname, '.pdf')==true}">

                    <font size="5" color="green">Given file is pdf file.</font>
                </c:when>
                
                                <c:otherwise>
                    <font size="5" color="red">Error found.</font>
                </c:otherwise>
            </c:choose>
        </c:if>
    </body>
</html>

This jsp code shows the following output :

If user enters file name with valid extension, output will be....

If found any error in search, output will be an error message.......

Download Source Code

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



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

Related Tutorials

Ask Questions?    Discuss: Use of Tag of JSTL  

Post your Comment


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