fn:contains() JSTL Function

fn:contains() JSTL Function Example explains about how to Tests whether the input string contains the particular substring.

Consider an example where you need to check whether the given input string is available on that particular string.

fn:contains() JSTL function will tests whether the input string contains the particular substring.

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

You can see the below example, which is demonstrating fn:contains() JSTL Function

Required Libraries

You need to download

  1. Tomcat 7
  2. JSTL 1.2

Following jar must be in classpath

  1. jstl-1.2.jar

fn:contains() 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:contains</title>
</head>

<body>
    
    <%
    // you can also set the values into request scope same as using c:set
    // request.setAttribute("str", "hello");
    %>

    <c:set var="str" value="hello" />

    ${fn:contains(str,"he")}<br/>
    ${fn:contains(str,"hellow")}

</body>
</html>
Output
true
false

 






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