Java jstl function contains

The JSTL (JavaServer Pages Standard Tag Library) fn tag library provides a set of functions for manipulating strings, collections, and other objects in JSP (JavaServer Pages) pages. One of the functions in the fn tag library is the fn:contains function, which is used to check if a string contains a substring.

The fn:contains function takes two arguments: a string and a substring to search for. The function returns a boolean value indicating whether the string contains the substring. The syntax of the function is as follows:

${fn:contains(string, substring)}
S‮‬ource:www.theitroad.com

where string is the string to search in, and substring is the substring to search for.

For example, to check if a string contains the substring "example", you would use the following expression:

${fn:contains('This is an example string', 'example')}

This expression returns true, because the string "This is an example string" contains the substring "example".

You can also use variables instead of literals for the string and substring arguments. For example, if you have a variable text containing a string, you can check if it contains the substring "example" using the following expression:

${fn:contains(text, 'example')}

This expression returns true if the variable text contains the substring "example".

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" %>

This imports the fn tag library and assigns it a prefix of fn.