programming4us
programming4us
WEBSITE

Java EE 6 with GlassFish 3 Application Server : JSP Standard Tag Library - JSTL functions

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
JSTL contains a number of functions that take Unified Expression Language expressions as parameters. All JSTL functions except one are used exclusively for String manipulation. An exception is the fn:length() function, which can take a String, Collection, or array as a parameter. It returns the length of the String, the size of the Collection, or the length of the array, depending on what parameter is passed to it. The following JSP illustrates the use of JSTL functions:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Function Tag Demo</title>
</head>
<body>
<c:set var="nameArr" value="${fn:split('Kevin,Danielle,Alex,Beatrice',',')}" />
We have a list of ${fn:length(nameArr)} names, here they are:
<br />
<ol>
<c:forEach var="currentName" items="${nameArr}">
<li />
${fn:toUpperCase(currentName)}
<br />
</c:forEach>
</ol>
</body>
</html>


					  

After packaging this JSP in a WAR file, deploying it and pointing the browser to its URL, we should see a page like the following:

This JSP illustrates the use of some of the JSTL functions. The fn:split() function splits a String into an array of strings using the character specified by its second parameter as a delimiter.

Notice that the strings inside the fn:split() function are enclosed inside single quotes. JSTL allows this as using double quotes for the strings would have resulted in illegal syntax, as the fn:split() function is already inside double quotes.


In the example, the fn:length() function returns the number of elements in the array we created when the fn:split() function was executed. Like we mentioned earlier, the fn:length() function can also take a Collection or a String as a parameter. When applied to a Collection, the function returns the number of elements in it. When applied to a String, the function returns the number of characters in the String.

The next function illustrated in the example is fn:toUpperCase(), which simply makes every alphabetical character in the String it takes as a parameter uppercase. There are many other JSTL functions, all of them are very intuitive to use. The following table lists all the JSTL functions:

Function Description Example
fn:contains(String, String) Returns a boolean indicating if the second parameter is contained in the first one. ${fn:contains("envir onment", "iron")}
fn:containsIgnoreCase( String, String) Case-insensitive version of fn:contains(). ${fn:containsIgnoreC ase("environment", "Iron")}
fn:endsWith(String, String) Returns a boolean indicating if the first parameter ends with a string equal to the second parameter. ${fn:endsWith("Glass Fish", "Fish")}
fn:escapeXml(String) Returns a string with all XML characters in the parameter escaped into their respective XML character entity code. ${fn:escapeXml( "<html>")}
fn:indexOf(String, String) Returns an int indicating the index of the second parameter in the first parameter. Returns -1 if the second parameter is not a substring of the first parameter. ${fn:indexOf("GlassF ish", "Fish")}
fn:join(String[], String) Returns a string composed of the elements in the first parameter, using the second parameter as a delimiter. ${fn:join(arrayVar," , ")}
fn:length(Object) Returns the length of an array, the size of a collection, or the length of a string, depending on the type of the parameter. ${fn:length("String, Collection or Array")}
fn:replace(String, String, String) Returns a string replacing every instance of the second parameter on the first parameter with the third parameter. ${fn:replace("Crysta lFish", "Glass")}
fn:startsWith(String, String) Returns a boolean indicating if the first parameter starts with the first parameter. ${fn:startsWith("Gla ssFish", "Glass")}
fn:split(String, String) Returns an array of strings containing elements in the first parameter as delimited by the second parameter. ${fn:split("Eeny, meeny", ",")}
fn:substring(String, int, int) Returns a string containing the substring in the first parameter, starting at the index indicated by the second parameter and ending just before the index indicated by the second parameter. ${fn:substring( "0123456789", 3, 6)}
fn:substringAfter (String, String) Returns a string containing the substring in the first parameter, starting after the first occurrence of the second parameter until the end of the first parameter. ${fn:substringAfter( "GlassFish", "Glass")}
fn:substringBefore (String, String) Returns a string containing the substring in the first parameter, starting before the first occurrence of the second parameter until the end of the first parameter. ${fn:substringBefore ("GlassFish", "Fish")}
fn:toLowerCase (String) Returns a string containing a version of the parameters with all alphabetical characters as lowercase. ${fn:toLowerCase( "GlassFish")}
fn:toUpperCase (String) Returns a string containing a version of the parameters with all alphabetical characters as uppercase. ${fn:toUpperCase (" GlassFish ")}
fn:trim(String) Returns a string containing a modified version of the parameter with all whitespace at the beginning and end of the parameter removed. ${fn:trim(" Gla ssFish ")}
Other  
 
Top 10
Free Mobile And Desktop Apps For Accessing Restricted Websites
MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
TOYOTA CAMRY 2; 2.5 : Camry now more comely
KIA SORENTO 2.2CRDi : Fuel-sipping slugger
How To Setup, Password Protect & Encrypt Wireless Internet Connection
Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
Backup & Restore Game Progress From Any Game With SaveGameProgress
Generate A Facebook Timeline Cover Using A Free App
New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
- Messages forwarded by Outlook rule go nowhere
- Create and Deploy Windows 7 Image
- How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
- Creating and using an unencrypted cookie in ASP.NET
- Directories
- Poor Performance on Sharepoint 2010 Server
- SBS 2008 ~ The e-mail alias already exists...
- Public to Private IP - DNS Changes
- Send Email from Winform application
- How to create a .mdb file from ms sql server database.......
programming4us programming4us
programming4us
 
 
programming4us