Home Jsp Simple-jsp-example JSTL Functions



JSTL Functions
Posted on: April 18, 2011 at 12:00 AM
In this example we are using the tag for setting the value in the variable named var.

JSTL Functions

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

In this example we are using the tag <c: set> for setting the value in the variable named var. We are going to use the various functions provided to us by the jstl functions library. 

The JSTL functions library has many methods. We have used some methods to describe the functioning of this library.

length(string): It returns the numbers of characters in the string.

contains(java.lang.String,  java.lang.String): It checks whether the given string contains the specified string.

split(java.lang.String, java.lang.String): It splits the string into an array of substrings.

toUpperCase(string): It converts the string to upper case.

toLowerCase(string): It converts the string to a lower case.

substring("String", first index, last index): It returns a subset of a string. 

The code of the program is given below:

<%@ 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>Using the JSTL functions</title></head>
<body>
<h2>Using JSTL functions</h2>
<c:set var="string" value="Welcome! to the site of roseindia.net"/>
The length of the String: ${fn:length(string)}<br>
Does the String contain "Welcome"? ${fn:contains(string,"Welcome")} <br>
Splits a string into an array of substrings using fn:split() : ${fn:length(fn:split(string," "))} <br>
Ignore the case : ${fn:containsIgnoreCase(string, "Welcome")}<br>
Converting the String into upper case using fn:toUpperCase(): ${fn:toUpperCase(string)}<br>
Converting the String into lower case using fn:toLowerCase(): ${fn:toLowerCase(string)}<br>
Making the substring of "roseindia.net" : ${fn:substring("roseindia.net", 0,9)}
</body>
</html>

The output of the program is given below:


Download this program.

Related Tags for JSTL Functions:


More Tutorials from this section

Ask Questions?    Discuss: Title  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.