fn:length() JSTL Function

fn:length() JSTL Function Example explains about How To Use fn:length() JSTL Function

You can use fn:length() in two ways
1) You can find the length of a string 2) You can find the size of an array or collections

fn:length() JSTL Function is used to find the length of a String, Collection or an array of objects(Object[]).

Example pattern : ${fn:length(someCollection)}

int length(java.lang.Object)

You can see the below example, which is demonstrating fn:length() JSTL Function

Required Libraries

You need to download

  1. Tomcat 9
  2. JSTL 1.2

Following jar must be in classpath

  1. jstl-1.2.jar

fn:length() Example

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ page import="java.util.ArrayList"%>
    ArrayList<String> numList = new ArrayList<String>();
    request.setAttribute("numList", numList);
    The length of the numList: ${fn:length(numList)}<br/>
    The length of the test String: ${fn:length('hello')}
The length of the numList: 3

The length of the test String: 5


Your email address will not be published. Required fields are marked *