Java jstl function trim
The fn:trim
function is a JSTL function that removes whitespace characters from the beginning and end of a string. The function takes a single argument, which is the input string.
The syntax of the fn:trim
function is as follows:
${fn:trim(string)}
where string
is the input string.
For example, the following expression removes whitespace characters from the beginning and end of the string " Hello World ":
${fn:trim(" Hello World ")}
This expression returns the string "Hello World".
You can also use variables instead of literals for the argument. For example, if you have a variable text
containing a string, you can trim the string using the following expression:
${fn:trim(text)}
This expression returns the string stored in the text
variable with whitespace characters removed from the beginning and end.
Note that the fn
tag library must be imported at the beginning of the JSP page using the following tag:
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>