JSTL Function fn:endsWith Example
- Details
- Written by Nam Ha Minh
- Last Updated on 30 August 2019   |   Print Email
This post helps you understand how to use the <fn:endsWith> tag in the JSTL function tags library with code example.
The fn:endsWith function tests whether a given string ends with a given suffix. This function returns boolean value.
JSTL <fn:endsWith> Syntax:
<c:if test="${fn:endsWith(<var containing source string>, <suffix to search>)}">
...
</c:if>
JSTL <fn:endsWith> Example:
The following code example searches for a suffix .net in the string www.codejava.net
.
<%@ 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"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>fn:endsWith Demo</title> </head> <body> <h1>fn:endsWith Demo</h1> <c:set var="stringToSearch" value="www.CodeJava.net" /> <c:out value="${stringToSearch}"/> <c:if test="${fn:endsWith(stringToSearch, '.net')}"> <p>CodeJava.net ends with .net</p> </c:if> </body> </html>
Output:
Other JSTL Function Tags:
contains | containsIgnoreCase | escapeXml | indexOf | join | length | replace | split | startsWith | substring | substringAfter | substringBefore | toLowercase | toUpperCase | trim
Comments