Month 10

JSTL List Count Using varStatus

JSTL List Count Using varStatus

JSTL List Count Using varStatus Example explains about how to Find JSTL List Count Using varStatus

Consider a JSP page, which contains an ArrayList and we need to find the exact count of that particular ArrayList

For this by declaring variable varStatus="status" in JSTL forEach, you can access all the available methods of status object inside JSP page

You can use JSTL 'status.count' for finding the number of elements available on that particular ArrayList.

This JSTL 'status.count' is available for all the List / Collection implementations in java

you can see the below example demonstrating JSTL 'status.count'

JSTL Size Of List / Array

JSTL Size Of List / Array

JSTL Size Of List / Array Example explains about how to check whether JSTL List / Array is empty or not

Consider the example here, a JSP page, which contains an ArrayList wihich contains lot of string values and we need to find whether ArrayList is empty or not

By using 'empty' operator is your best tool for making comparison to 0. so that you can identify whether the ArrayList is empty or not

When you need to find the size of an ArrayList, the JSTL function fn:length is your best fit. Please check "fn:length() JSTL Function" for finding the Length / Size of List / Array

you can see the below example demonstrating the usage of 'empty' operator inside JSTL
 

JSTL Last Using varStatus

JSTL Last Using varStatus

JSTL Last Using varStatus Example explains about finding JSTL last count using varStatus

Consider a JSP page, which contains an ArrayList and we need to find the last count of that particular ArrayList

For this by declaring variable varStatus="status" in JSTL forEach, you can access all the available methods of status object inside JSP page

You can use 'status.last' inside c:forEach tag, this will find the last element of that particular ArrayList

This JSTL 'status.last' is available for all the List / Collection implementations in java

you can see the below example demonstrating JSTL 'status.last'

JSTL Functions

JSTL Functions

JSTL Functions Example explains about using different functions available in JSTL Taglib

To perform string functions in JSP without using any java code inside JSP, we can use JSTL functions. For this we need to prefix fn allows us to perform string functions in JSP

For working with JSTL functions, we need to import following additional taglib url

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

to our jsp, please check the below example code

 

JSTL forEach Map Iteration

JSTL forEach Map Iteration

JSTL forEach Map Iteration Example explains how to iterating a map using JSTL Taglib

Map is an object that stores key / value pairs. You can find its value from a particular key. Keys must be unique, but values may be duplicated 

Consider a JSP page, which contains a HashMap with lot of key value pairs inside it and we need to iterate and display the values inside that particular HashMap

You can access ${entry.key} and ${entry.value} from a Map using a variable var="entry"

This JSTL 'c:forEach is available for all the List / Collection implementations in java

Following example shows How to iterate a JSTL HashMap using JSTL c:forEach