Share on Google+Share on Google+

Use of and Tag of JSTL

In this section, you will learn how to use and Tag of JSTL.

Use of <fn:split(String, String)> and <fn:join(String, String)> Tag of JSTL


In this section we will learn how to use <fn:split>and <fn:join> Tag of JSTL. These tags are used to split and join the specified string according to the given delimeter.

<fn:split> It splits a string into an array of sub strings on the basis of specified delimeter.
<fn:join> It joins all elements of an array into a string with the specified separator.

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

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





<%@ taglib prefix="c" uri="" %>
<%@ taglib prefix="fn" uri="" %>
        <title>Example fn:split and fn:join tag of JSTL</title>
        <c:set var="str1" value="This is first string"/>
        <c:set var="str2" value="This|is|second|string"/>
        <c:set var="str3" value="This|is+third*string"/>
        <h4>tag fn:split(Here we will split the given string in 
         to array of string on the <br>basis of given delimeter)</h4>
        <table width="50%" border="1">
                <th>Input String</th>
                <th>After split</th>
                <td>white space</td>
                    <c:forEach var="num" items="${fn:split(str1, ' ')}">
                        <c:out value="${num}" /> 
                    <c:forEach var="num" items="${fn:split(str2, '|')}">
                        <c:out value="${num}" /> 
                    <c:forEach var="num" items="${fn:split(str3, '+|*')}">
                        <c:out value="${num}" /> 
        <h4>tag fn:split(Here we will join the splitted array of string 
         in to a single string <br>with the given separator)</h4>
        <table cellpadding="5" border="1">
                <th>After join</th>
            <tr><c:set var="a1" value="${fn:split(str1, ' ')}" />
                <td> white space</td>
                <td><c:out value="${fn:join(a1, ' ')}" /></td>
            <tr><c:set var="a1" value="${fn:split(str2, '|')}" />
                <td><c:out value="${fn:join(a1, ' | ')}" /></td>
            <tr><c:set var="a1" value="${fn:split(str3, '|+*')}" />
                <td><c:out value="${fn:join(a1, ' *** ')}" /></td>

This jsp code shows the following output :

Download Source Code


Posted on: August 24, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Use of and Tag of JSTL  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
September 13, 2012
thank you

thanks for your help