<%@ page import="java.util.*" %> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/ea/core" %> JSTL: EcmaScript EL Support -- Simple Array and List Access Example

Array and List Access

EcmaScript uses the [] notation to access array elements. If the first operand is an array then the second operand (the one that goes between the brackets) should be an expression that evaluates to an integer. If the first operand is a reference to an object then the second operand should be an expression that evaluates to a string that names a property of the object. The same principles work for accessing List objects (Vectors, for example).

Here is an example:

Favorite Actor and Role

<% String[] array = new String[] {"Harrison", "Ford", "Indiana", "Jones"}; request.setAttribute("myArray", array); List list = new Vector(); for (int i = 0; i < array.length; i++) { list.add(array[i]); } request.setAttribute("myList", list); %> <%-- demonstrating how to use expression to get index --%> <%-- demonstrating how to use status object to get index --%>
Index Array Value List Value