tumblr counter

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 7
  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>();
    numList.add("one");
    numList.add("two");
    numList.add("three");
    request.setAttribute("numList", numList);
%>
<html>
<body>
    The length of the numList: ${fn:length(numList)}<br/>
    The length of the test String: ${fn:length('hello')}
</body>
</html>
Output
The length of the numList: 3

The length of the test String: 5

 












fn:length() Example JSTL fn:length() Function Size Of List In JSTL Check A Collection Size With JSTL Use Of fn:length(String) JSTL Tag

You might also like following tutorials :

Java Tutorial Apache CXF Tutorial Hibernate Tutorial Spring Tutorial Struts Tutorial
0 Comments on "fn:length() JSTL Function"