Home Jsp Simple-jsp-example JSTL Functions
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

JSTL Functions

Advertisement
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.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 18, 2011

Related Tutorials

Ask Questions?    Discuss: Title  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com