Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Jsp Use of Tag of JSTL

Related Tutorials


Share on Google+Share on Google+

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


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

Discuss: Use of Tag of JSTL  

Post your Comment

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