BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

fn:contains() – JSTL Function

By Chaitanya Singh | Filed Under: JSTL

fn:contains() function checks whether the given string is present in the input as sub-string. It does a case sensitive check, which means it considers the case while checking for the sub-string.

Syntax:

boolean fn:contains(String inputstring, String checkstring)

The return type of this function is boolean. It returns true when the checkstring is present in inputstring else it returns false. It has two string arguments – first one has input string and second argument has the string which needs to be checked in input string.

Example of fn:contains()

In this example we are checking whether the new password contains old password as a sub-string, if it does then we are displaying a message to the user.

<%@ 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>fn:contains example</title>
</head>
<body>
<c:set var="oldPassword" value="HelloPass"/>
<c:set var="newPassword" value="HelloPassNew" />
<c:if test="${fn:contains(newPassword, oldPassword)}">
 <c:out value="New Password should not contain old password as substring"/>
</c:if>
</body>
</html>

Output:

fn-contains-example

Leave a Reply Cancel reply

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

JSTL Core Tags

  • c:out
  • c:set
  • c:remove
  • c:if
  • c:choose
  • c:when
  • c:otherwise
  • c:catch
  • c:import
  • c:forEach
  • c:forTokens
  • c:param
  • c:url
  • c:redirect
JSTL Functions
  • fn:contains()
  • fn:containsIgnoreCase()
  • fn:indexOf()
  • fn:escapeXML()
  • fn:join() & fn:split()
  • fn:length()
  • fn:startsWith()
  • fn:endsWith()
  • fn:substring()
  • fn:substringAfter()
  • fn:substringBefore()
  • fn:trim()
  • fn:toUpperCase()
  • fn:toLowerCase()
  • fn:replace()

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap