Open In App

JSTL fn:contains() Function

In JSTL, the fn:contains() function is mainly used to check the input substring is present within the given string. This function returns the boolean value representing the result in True or False form.

This function simplifies the substring presence check tasks in Java Server Pages. In this article, we will see the syntax, parameters, and practical example of JSTL fn:contains() function.



Syntax of JSTL fn:contains()

${fn:contains(string, substring)}

Parameters:

Example of fn:contains()

In this example, we will discuss the use of fn:contains(), with two substringsthe one is present and other is not present in the main string.




<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ 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>Using JSTL Functions</title>
  </head>
  <body>
  <c:set var="mainString" value="Welcome to GeeksforGeeks"/>
  <h3>Main String: ${mainString}</h3>
      
  <p>Check for "Geeks": ${fn:contains(mainString, 'Geeks')}</p>
  <p>Check for "Java": ${fn:contains(mainString, 'Java')}</p>
      
  </body>
</html>

Output:

Main String: Welcome to GeeksforGeeks 
Check for "Geeks": true
Check for "Java": false

Output Screen of JSTL fn:contains() Program:



Explanation of the above Program:


Article Tags :