Open In App

JSTL fn:toLowerCase() Function

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

In JSTL, the fn:toLowerCase function converts all the characters of the input or specified string into the lowercase format. This allows the developers to transform the string case with the JavaServer Pages and also ensures the proper representation of text in lowercase.

In this article, we will see the Syntax along with parameters and also the practical implementation of the function in terms of examples.

Syntax of fn:toLowerCase() Function

${fn:toLowerCase(string)}

Where,

  • ${fn:toLowerCase()}: This is the expression that is used to convert the input string into lowercase characters.
  • string: This is the main input string which will be converted to lowercase format.

Example of JSTL fn:toLowerCase() Function

In this example, we will discuss the use of fn:toLowerCase() in a code sample with ONLY uppercase letters of a JSP application.

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:toLowerCase() Example</title>
  </head>
  <body>
    <c:set var="inputString" value="GEEKSFORGEEKS"/>
    <h3>Original String: ${inputString}</h3>
      
    <p>Lowercase String: ${fn:toLowerCase(inputString)}</p>
      
  </body>
</html>


Output:

Original String: GEEKSFORGEEKS
Lowercase String: geeksforgeeks

Output Screen of the JSTL fn:toLowerCase() Function:

JSTL fn:toLowerCase() Function

Output

Explanation of the above Program:

  • In the above example, we have initialized the inputString with the value “GEEKSFORGEEKS“. Here all the characters are in uppercase by default.
  • We are displaying the Original String in the h3 tag.
  • Then, we use the fn:toLowerCase() function and pass the inputString variable as a parameter, so that the inputString will be converted into lowercase. So the lowercase string will be “geeksforgeeks“.
  • We are printing the lowercase string using the <p> in HTML.

Example 2:

In this example, we will discuss the use of fn:toLowerCase() in a code sample with a mixed of uppercase and lowercase letters in a JSP application.

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:toLowerCase() Example</title>
  </head>
  <body>
    <c:set var="inputString" value="GeeKsForGeeks"/>
    <h3>Original String: ${inputString}</h3>
      
    <p>Lowercase String: ${fn:toLowerCase(inputString)}</p>
      
  </body>
</html>


Output:

Original String: GeeKsForGeeks
Lowercase String: geeksforgeeks

Output Screen of the JSTL fn:toLowerCase() Function(Example 2):

Output Screen of the JSTL fn:toLowerCase() Function(Example 2)

Explanation of the above Program:

  • inputString variable set to “GeeKsForGeeks,” which is a string with a mix of uppercase and lowercase characters.
  • <h3> tag is used to display the original string.
  • <p> tag is used to display the result of applying the fn:toLowerCase() method to convert the string to lowercase.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads