• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • 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)
  • 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)

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()>

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

Example of JSTL Function <fn:split()>

<%@ 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>

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()

Category: Java EETag: 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.

Previous Post: « JSTL Function fn:join()
Next Post: JSTL Function fn:startsWith() »

Reader Interactions

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.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

New Features in Spring Boot 1.4

Difference Between @RequestParam and @PathVariable in Spring MVC

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact