Open In App

JSTL fn:startsWith() Function

Last Updated : 14 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In JSTL the fn:startsWith() function is used to check if a given string starts with a particular prefix. This function returns the boolean value as True or False according to the check result.

  • If the input string begins with the prefix then true is been returned else false is been returned.

In this article, we will see the detailed Syntax of the fn:startsWith() function along with its parameters, we will also see the practical implementation of this function in terms of examples.

Syntax of JSTL fn:startsWith() Function

${fn:startsWith(string, prefix)}

Where,

  • ${fn:startsWith()}: This is the JSTL expression that is used to check whether the string starts with the specified prefix.
  • string: This is the input string that will be checked.
  • prefix: This is the value or character that we will check if it is at the beginning of the input string.

Example of JSTL fn:startsWith() Function

Below is the implementation of JSTL fn:startsWith() Function:

HTML




<%@ 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>JSTL fn:startsWith() Example</title>
  </head>
  <body>
    <c:set var="inputString" value="GeeksforGeeks"/>
    <h3>Original String: ${inputString}</h3>
    <p>Starts with "Geeks": ${fn:startsWith(inputString, 'Geeks')}</p>
    <p>Starts with "Java": ${fn:startsWith(inputString, 'Java')}</p>
  </body>
</html>


Output:

Original String: GeeksforGeeks
Starts with "Geeks": true
Starts with "Java": false

Output Screen of the JSTL fn:startsWith() Function Program:

Output of JSTL fn:startsWith() Function Example

Explanation of the above Program:

  • In the above example, we have initialized the variable inputString with the value GeeksforGeeks using the c:set
  • Then, we check using the fn:startsWith() whether the prefix Geeks is present in the inputString. As we can see the prefix is present and starts in the inputString, so the function has returned the output as true. We have printed this output using a simple <p> tag in HTML.
  • In the next condition, we are checking in inputString, whether the prefix Java starts at the beginning. We can easily notice that there is no Java prefix at the beginning of the inputString, so the function has returned the result as false. We have printed it using <p> tag.


Similar Reads

Path startsWith() method in Java with Examples
startsWith() method of java.nio.file.Path used to check if this path object starts with the given path or string which we passed as parameter. There are two types of startsWith() methods. startsWith(String other) method of java.nio.file.Path used to check if this path starts with a Path, constructed by converting the given path string which we pass
3 min read
CompositeName startsWith() method in Java with Examples
The startsWith() method of a javax.naming.CompositeName class is used to check whether composite name which is passed as a parameter is a prefix of this composite name or not. A composite name 'X' is a prefix of this composite name if this composite name object ends with 'X'. If X is null or not a composite name object, false is returned. Syntax: p
2 min read
CompoundName startsWith() method in Java with Examples
The startsWith() method of a javax.naming.CompoundName class is used to check whether compound name which is passed as a parameter is a prefix of this compound name or not. A compound name 'X' is a prefix of this compound name if this compound name object ends with 'X'. If X is null or not a compound name object, false is returned. Syntax: public b
2 min read
Java String startsWith() and endsWith() Methods With Examples
The String class in Java is an immutable and non-primitive data type that is used to store the characters of the sequence. The string is non-primitive datatype because, during the initialization of the string variable, it refers to an object that contains methods that can perform several different kinds of operations, but according to the definitio
3 min read
String startswith() Method in Java with Examples
In Java, startWith() method of the String class is present in java.lang package is used to check whether the string starts with a specific prefix. The package view is as follows: --&gt; java.lang Package --&gt; String Class --&gt; startWith() Method Variants Of String startsWith() methodThere are two variants of the startswith() method that are as
3 min read
JSTL Function Tags
JSTL(JSP Standard Tag Library) is a collection of custom tags that provide common functionalities like flow control, database operations, etc. JSTL tags can be embedded in Java Server Pages just like other HTML tags. It is convenient for front-end developers to work with HTML-like tags for including logic in webpages rather than writing Java code i
8 min read
JSTL fn:replace() Function
The JSTL fn:replace() function or method in JSP (Java Server Pages) is mainly used for the manipulation of strings. This function allows developers to replace the occurrence of a specified substring with another substring in the given input string. This article will see the Syntax, parameters, and two practical examples of the fn:replace() function
2 min read
JSTL fn:substringAfter() Function
In the main string, if we want to return the subset of the string followed by a specific substring then we can use the JSTL fn:substringAfter() Function. JSTL substringAfter() FunctionThis function mainly returns the portion of the string that comes after the given string value. In this article, we will see the detailed Syntax of the fn:substringAf
2 min read
JSTL fn:containsIgnoreCase() Function
In the input string, if we need to check whether the input string has the specified string or not by ignoring its case then we can use the JSTL fn:containsIgnoreCase() Function. In this article, we will see the detailed Syntax of the fn:containsIgnoreCase() function along with its parameters, we will also see the practical implementation of this fu
2 min read
JSTL fn:substring() Function
In JSTL, the fn:substring() function is used to extract or retrieve the part of a given input or specified string, by starting from the start index to the end index [optional]. This function is mainly used for string manipulation tasks by many developers. In this article we will explore the Syntax along with the Parameters of the JSTL fn:substring(
2 min read
Practice Tags :