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
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 = 2hello world