The function <fn:length()> is the string function. This function used to find out the length of the entered string. This function displays the number of characters entered in the specified string.
Syntax of Function <fn:length()>
[code lang=”html”]
int length(Object)
[/code]
Example of Function <fn:length()>
[code lang=”html”]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ 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:length() example</title>
</head>
<body>
<c:set var="string1" value="JavaBeat" />
<c:set var="string2" value="welcome to JavaBeat.net" />
Length of word JavaBeat is: ${fn:length(string1)}
<br>
<br> Length of word welcome to JavaBeat.net is:
${fn:length(string2)}
<br>
<br>
</body>
</html>
[/code]
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:substring() :: Next Tutorial : JSTL Function fn:toLowerCase()
Leave a Reply