Home Jsp Use of Tag of JSTL



Use of Tag of JSTL
Posted on: August 24, 2008 at 12:00 AM
In this section, will learn how to use Tag of JSTL.

Use of <fn:length(String)> Tag of JSTL

     

In this section we will learn how to use <fn:length> Tag of JSTL. This tag returns the number of items in a collection, or the number of characters in a string. This takes Object type as arguments and returns int type.

Syntax :
int length(java.lang.Object)









length_fnJstlTag.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
    <head>
        <title>Example of fn:length tag of JSTL</title>
    </head>
    <body>
        <form method="POST">
            This will calculate the length of specified string.
            <table>
                <tr>
                    <td>Enter String</td>
                    <td><input type="text" name="text"></td>
                </tr>
                
                <tr>
                    <td></td>
                    <td><input type="submit" value="calculate"></td>
                </tr>
            </table>  
        </form>
        <c:if test="${pageContext.request.method=='POST'}">
            <c:set var="text" value="${param.text}"/>
            
            <font size="5" color="#1B2A0A">
                Length : 
            </font>
            <font size="5" color="green">

                <c:out value="${fn:length(text)}"/>
                
            </font>
        </c:if>
    </body>
</html>


This jsp code shows the following output :



Suppose in user wants to calculate the length of string 'mahendra singh'.....



When user clicks on calculate button, output will be.....



Download Source Code

Related Tags for Use of Tag of JSTL:
cstringstlobjectioargumentstypecharjstlcollectiontagnumberreturnintthislengthcharactercharactersjsctetolearnargumenteareilititemitemssectionusepeinasmnttrjesememsmehowobjsurncolrackishallcollecteaandaractcollectstrssriringthstjendonolo


More Tutorials from this section

Ask Questions?    Discuss: Use of Tag of JSTL   View All Comments

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.