The JSTL fn:replace() function returns the input string by replacing all occurrence of the specified string with the given string.
Syntax: String replace(String inputString, String specifiedString, String givenString)
Example:
test.jsp
<%@ 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>fn:replace JSTL function example</title>
</head>
<body>
<c:set var="testString"
value="Hello this is a JSTL function example."/>
Given String: <br/>
<c:out value="${testString}" /><br/><br/>
String after replacing JSTL to jstl:<br/>
<c:out value="${fn:replace(testString, 'JSTL', 'jstl')}"/>
</body>
</html>
|
web.xml
<web-app>
<welcome-file-list>
<welcome-file>test.jsp</welcome-file>
</welcome-file-list>
</web-app>
|
Output:
No comments:
Post a Comment