JSTL SubstringBefore function is used to get the substring of target string. This function takes 2 parameters.
First parameter in JSTL SubstringBefore function is the target String from which you want to derive the substring.
Second parameter in JSTL SubstringBefore function is the substring which breaks the string in to 2 parts and function returns the substring before it.
JSTL substringBefore Function Example:
<%@ 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" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>JSTL substringBefore Function Example</title> </head> <body> <c:out value="${fn:substring('Hello-Jwalant','-')}"></c:out> </body> </html>
Output: Hello
As you can see above, JSTL substringBefore function takes 'Hello-Jwalant' string as target String parameter, '-' is the substring which decides the result. substringBefore function returns the substring before '-'.