JSTL Function fn:length Example
- Details
- Written by Nam Ha Minh
- Last Updated on 31 August 2019   |   Print Email
This post helps you understand how to use the <fn:length> tag in the JSTL function tags library with code example.
The fn:length function returns the number of characters in a string or number of items in any collection.
JSTL <fn:length> Syntax:
${fn:length(collection | string)}
JSTL <fn:length> Example:
The below code example prints the number of characters in a string.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>fn:length Demo</title> </head> <body> <h1>fn:length Demo</h1> <c:set var="text" value="Code Java" /> <c:out value="${text}"/> <p>Length: ${fn:length(text)}</p> </body> </html>
Output:
Other JSTL Function Tags:
contains | containsIgnoreCase | endsWith | escapeXml | indexOf | join | replace | split | startsWith | substring | substringAfter | substringBefore | toLowercase | toUpperCase | trim
Comments