The fn:toUpperCase & fn:toLowerCase tags of JSTL


 

The fn:toUpperCase & fn:toLowerCase tags of JSTL

In this section ,we will learn how to use fn:toUpperCase and fn:toLowerCase Tag of JSTL.

In this section ,we will learn how to use fn:toUpperCase and fn:toLowerCase Tag of JSTL.

The fn:toUpperCase & fn:toLowerCase tags of JSTL

In this section ,we will learn how to use fn:toUpperCase and  fn:toLowerCase Tag of JSTL. These tags are used to change case of specified string to upper or lower. This takes string type as argument.

EXAMPLE:

In this Example, the user enters the value of string, which he wants to change it's case(i.e lowercase or uppercase). The c:if tag of JSTL checks whether requirement is 'uppercase' or' lowercase' & convert it accordingly using  "fn:toUpperCase()" or " fn:toLowerCase()" method of JSTL.

changeCaseJSTL.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html>

<head>

<title>Example of 'fn:toUpperCase' and 'fn:toLowerCase' tag of jstl</title>

</head>

<body bgcolor="grey">

<form method="POST">

Enter String here and select case as per your choice.

<table>

<tr>

<td>Enter String</td>

<td><input type="text" name="string"></td>

</tr>

<tr>

<td></td>

<td><input type="radio" name="case" value="upper"> Upper Case

<input type="radio" name="case" value="lower"> Lower Case </td>

</tr>

<tr>

<td></td>

<td><input type="submit" value="change"></td>

0

</tr>

</table>

</form>

1

<c:if test="${pageContext.request.method=='POST'}">

<c:set var="string" value="${param.string}"/>

2

<font size="5" color="green">

<c:if test="${param.case=='upper'}">

3

<c:out value="${fn:toUpperCase(string)}"/>

</c:if>

4

<c:if test="${param.case=='lower'}">

<c:out value="${fn:toLowerCase(string)}"/>

5

</c:if>

</font>

6

</c:if>

</body>

</html>

7

OUTPUT :

After submitting Value the output will be :

8

Download Source Code

Ads