JSTL Function Tags

In JSTL, the purpose of function tags is similar to the various string methods in Java. Hence, these tag performs common string manipulation operations.

Functional tag is represented by following URL: -

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

Function Tags

These are some frequently used function tags: -

  • fn:length(): - This tag returns the length of the string i.e. number of characters present in the string.
  • fn:trim(): - This tag removes the spaces from both ends of the string.
  • fn:replace(): - This tag is used to replace one string with another.
  • fn:substring(): - This tag provides the substring (i.e. part of string) the string.
  • fn:join(): - This tag is used to concatenates separate strings of an array
  • fn:split(): - This tag breaks the string into array of substrings.
  • fn:contains(): - This tag checks whether the input string contains the specified substring.
  • fn:toUpperCase(): - This tag converts the lower case elements of a string into upper case.
  • fn:toLowerCase(): - This tag converts the upper case elements of a string into lower case.

Example of JSTL Function Tag

This is an example of JSTL Function tag that shows various JSTL function tags functionality.

index.jsp

<%@ 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>Function Tag</title>
</head>
<body>
<c:set var="web" value="Tutorial and Example"/>
Length of String :: ${fn:length(web)} <br>
Substring of String :: ${fn:substring(web,0,8)} <br>
Is it contains word "Tutorial" :: ${fn:contains(web,'Tut')}<br>
In UpperCase :: ${fn:toUpperCase(web)}
</body>
</html>
Output: