Use of Tag of JSTL

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

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


In this section we will learn how to use <fn:subString>  Tag of JSTL. This tag returns a subset of a string of specified length. This takes string and integer type as arguments and return string type.

Syntax :
java.lang.String substring(java.lang.String, int, int)







<%@ taglib uri="" prefix="fn" %>
<%@ taglib uri="" prefix="c" %>
        <title>Example of 'fn:subString' tag of jstl</title>
        <form method="POST">
            Enter String here and mention upper and lower limit to 
            cut substring<br> from this given string. 
                    <td>Enter String</td>
                    <td><input type="text" name="string"></td>
                    <td>Start from</td>
                    <td><input type="text" name="start" size="3"></td>
                    <td>End to</td>
                    <td><input type="text" name="end" size="3"></td>
                    <td><input type="submit" value="cut"></td>
        <c:if test="${pageContext.request.method=='POST'}">
            <c:catch var="exception">
                <c:set var="string" value="${param.string}"/>
                <c:set var="start" value="${param.start}"/>
                <c:set var="end" value="${param.end}"/>
                <font size="5" color="green">

                    <c:out value="${fn:substring(string,start,end)}"/>

            <c:if test="${exception!=null}">
                <font size="5" color="red">Error Found.</font>


This jsp code shows the following output :

Here user will enter string and specify the start and end point form where user wants to retrieve the sub string.... 

When user clicks on cut button, 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