JSTL fn:length() function

The JSTL fn:length() function is used to get the length of the object. It returns no. of characters in case of string input and no. of elements in case of collection.
Syntax: int length(String inputString/Collection object)

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:length JSTL function example</title>
 </head>
 <body>
  <c:set var="testString" 
                    value="Hello this is a JSTL function example."/>
  Length of the given string: <br/>
  <c:out value="${fn:length(testString)}" />
 </body>
</html>
web.xml
<web-app>
 
  <welcome-file-list>
          <welcome-file>test.jsp</welcome-file>
  </welcome-file-list> 
 
</web-app>

Output:


No comments: