Use of

In this section, you will learn how to use Tag of JSTL.

Use of <fn:trim(String)JSTL Tag


In this section we will learn how to use <fn:trim> Tag of JSTL. This tag removes white spaces from both ends of specified string. This takes string type as arguments and return string type result.

Syntax :
java.lang.String trim(java.lang.String)







<%@ taglib prefix="c" uri="" %>
<%@ taglib prefix="fn" uri="" %>
        <title>Example of fn:trim tag of JSTL</title>
        <form method="POST">
            This application removes blank spaces from both ends of string.
                    <td>Enter string</td>
                    <td><input type="text" name="text"></td>
                    <td><input type="submit" value="trim"></td>
        <c:if test="${pageContext.request.method=='POST'}">
            <c:set var="text" value="${param.text}"/>
            <c:set var="trimText" value="${fn:trim(text)}"/>
            <table border="1">
                    <th>Before trim</th>
                    <th>After trim</th>
                    <th>Before trim string length</th>
                    <th>After trim string length</th>
                    <td><c:out value="${text}" /></td>
                    <td><c:out value="${trimText}"/></td>
                    <td><c:out value="${fn:length(text)}" /></td>
                    <td><c:out value="${fn:length(trimText)}" /></td>

This jsp code shows the following output :

Here user will enter string with some white spaces like...... 

When user clicks on trim button, output will be.......

Download Source Code



We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.

Share on Google+Share on Google+

Use of

Posted on: August 24, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles