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 lran how to use Tag of JSTL.

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


In this section we will learn how to use <fn:replace> Tag of JSTL. This tag returns a string after replacing the given sub string with specified sub string. This takes string type as arguments and returns string type.


Syntax :
java.lang.String replace(java.lang.String, java.lang.String, java.lang.String)


<%@ taglib prefix="c" uri="" %>
<%@ taglib prefix="fn" uri="" %>
        <title>Example of fn:replace tag of Jstl tag library</title>
        <form method="POST">
                    <td>Enter String in you want to replace</td>
                    <td><input type="text" name="string"></td>
                    <td>Replace character/string</td>
                    <td><input type="text" name="find"></td>
                    <td>Replace with</td>
                    <td><input type="text" name="replaceWith" size="3"></td>
                    <td><input type="submit" value="Replace all"></td>
        <c:if test="${pageContext.request.method=='POST'}">
            <c:set var="string" value="${param.string}"/>
            <c:set var="find" value="${param.find}"/>
            <c:set var="replaceWith" value="${param.replaceWith}"/>
            <font size="5" color="#1B2A0A">
                Result : 
            <font size="5" color="green">

   <c:out value="${fn:replace(string,find,replaceWith)}"/>


This jsp code shows the following output :

Suppose in user wants to replace all 'x' with character 'a' in string "Mahendra Singh"....

When user clicks on Replace all 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