JavaBeat

  • Home
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Privacy

JSTL Function fn:split()

March 5, 2014 by Krishna Srinivasan Leave a Comment

The JSTL Function <fn:split()> is the string function. This function is used to split or separate the string with specified delimiter(separator). JSTL Function <fn:split()> helps to split or separate a specified string into an array of substring.

Syntax of JSTL Function <fn:split()>

[code lang=”html”]
java.lang.String[] split(java.lang.String, java.lang.String)
[/code]

Example of JSTL Function <fn:split()>

[code lang=”html”]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>fn:split Demo</title>
</head>
<body>
<h1>Example of Function fn:split()</h1>
<c:set var="name" value="welcome-to-JavaBeat" />
<c:set var="splitName" value="${fn:split(name,’-‘)}" />
<c:set var="joinedName" value="${fn:join(splitName,’ ‘)}" />
<p>Name before split: <br><br><b>${name}</b></p>
<p>Name after split: <br><br><b>${joinedName}</b></p>
</body>
</html>
[/code]

Details of the Code

  • <c:set var=”name”> tag is used to set the variable name which we want to display in the output.
  • < c:set var=”splitName” value=”${fn:split(name,’-‘)}”> this line of code used to display the name separated by a specified separator.
  • Name before split: ${name} this line of code displays the name before it split.
  • after split:joinedName} this line of code displays the name after splitting.

Steps for Execution

  • Click on the jsp File
  • Right click on mouse and select run as ->click run on server
  • The simple way for execute the program on eclipse is to use Ctrl+F11 key then click on select your browser option and click on finish

Output

When the execution process completed successfully we will get the output on eclipse browse as follows:
output of jstl function fn split

Previous Tutorial :  JSTL Function fn:join()  :: Next Tutorial : JSTL Function fn:startsWith()

Filed Under: Java EE Tagged With: JSTL Tutorials

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow Us

  • Facebook
  • Pinterest

As a participant in the Amazon Services LLC Associates Program, this site may earn from qualifying purchases. We may also earn commissions on purchases from other retail websites.

JavaBeat

FEATURED TUTORIALS

Answered: Using Java to Convert Int to String

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Copyright © by JavaBeat · All rights reserved