fn:endsWith() JSTL Function

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

Consider an example where you need to check whether a string ends with a specified suffix.

fn:endsWith() function will tests whether a particular string ends with the specified suffix.

boolean endsWith(java.lang.String, java.lang.String)

You can see the below example, which is demonstrating fn:endsWith() 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:endsWith() 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:endsWith</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" />

<c:if test="${fn:endsWith(str, 'String')}">
    <p>ends with "String"</p>
</c:if>

<c:if test="${fn:endsWith(str, 'This')}">
    <p>ends with 'This'</p>
</c:if>

</body>
</html>
Output
ends with "String"

 











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