JSTL fn:contains() function

The JSTL fn:contains() function is used to check whether the input string contains the specified string or not. It returns true if input string contains the specified string otherwise return false. It is case sensitive.

Syntax:

boolean contains(String inputString, String specifiedString)

Example:

test.jsp

<%@ 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 JSTL function example</title>
	</head>
	<body>
		<c:set var="testString" 
                      value="Hello this is a JSTL function example."/>
 
		<c:if test="${fn:contains(testString, 'JSTL')}">
		   <h4>String JSTL found in the test string.</h4>
		</c:if>
 
		<c:if test="${fn:contains(testString, 'jstl')}">
		   <h4>String jstl found in the test string.</h4>
		</c:if>
	</body>
</html>

web.xml

<web-app>
 
  <welcome-file-list>
          <welcome-file>test.jsp</welcome-file>
  </welcome-file-list>	
 
</web-app>

Output:

jsp example 52   Download this example.   Next Topic: JSTL fn:containsIgnoreCase() function with example. Previous Topic: JSTL Functions with example.

 

Please follow and like us:
Content Protection by DMCA.com