<fn:replace()> is a string function. The function replace is used to replace the entered string with specified string. The <fn:replace()> function replaces the existing string with another string.
Syntax of JSTL Function <fn:replace()>
String fn:replace(String input, existing String, String replace_with)
Example of JSTL Function <fn:replace()>
Following example demonstrate the working of <fn:replace()> function. In this example we replace the string Welcome to Javabeat with the new string as Hello JavaBeat.net.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> <html> <head> <title>JSTL fn:replace() example</title> </head> <body> <c:set var="author" value="Welcome to Javabeat" /> <p> String <b>Welcome to Javabeat</b> changed to <b>Hello JavaBeat.net</b> </p> ${fn:replace(author, "Welcome to Javabeat", "Hello JavaBeat.net")} </body>
Steps for Execution
- Save this file as example.jsp in your eclipse IDE.
- Now select this jsp file, right mouse click and select Run as ->Run on server
Output
When the execution process is completed successfully we will get the following output :
Previous Tutorial : JSTL Function fn:trim()