fn:split() JSTL Function

fn:split() JSTL Function Example explains about how to split a string in jsp using fn:split() JSTL Function

Consider an example where you need to split a given input string into an array of strings.

fn:split() JSTL Function helps you to splits a specified string into an array of substrings.

java.lang.String[] split(java.lang.String, java.lang.String)

You can see the below example, which is demonstrating fn:split() 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:split() Example

<%@ 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:split</title>
</head>

<body>

length of array is = ${fn:length(fn:split("hello world"," "))}
<br />
<!-- fn:split() returns array of strings, so we need to iterate -->

<c:forEach var="item" items="${fn:split('hello world',' ')}">
        ${item}
</c:forEach>

</body>
</html>
Output
length of array is = 2
hello world

 









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