fn:trim() JSTL Function

fn:trim() JSTL Function Example explains about How To Use fn:trim() JSTL Function.

Consider an example string where you need to remove all the whitespaces in between that string.

In that case, fn:trim() function will removes the white space included in between both ends of a particular string.

java.lang.String trim(java.lang.String)

You can see the below example, which is demonstrating fn:trim() JSTL Function

Required Libraries

You need to download

  1. Tomcat 9
  2. JSTL 1.2

Following jar must be in classpath

  1. jstl-1.2.jar

fn:trim() Example

<%@ 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>JSTL fn:trim()</title>
</head>
<body>

    <%
    // you can also set the values into request scope same as using c:set
    // request.setAttribute("str", " This is a Test String  ");
    %>
    
    <c:set var="str" value=" This is a TEST String  " />
    Before trim = ${fn:length(str)}<br/>
    <c:set var="str" value="${fn:trim(str)}" />
    After trim = ${fn:length(str)}<br/>
    <!--space before "This" and after "String" will be removed-->
    Now string is = ${str}

</body>
</html>
Output
Before trim = 24
After trim = 21
Now string is = This is a TEST String

 









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