tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Serge Knystautas <>
Subject Re: Arrays in EL
Date Tue, 09 Sep 2003 13:42:57 GMT
Ely Eshel wrote:
> Hi!
> How can I set up an array of strings in EL, so that I can refer to each
> string as ${array[i]) with i being either a literal value or a variable?
> I want to accomplish the equivalent of the following, using an array index
> instead of a hard-coded number:
> <%
> String[] DB_FIELDS = {"name_last", "name_init", "name_first"};
> %>
> <c:set var="db_fields_1">
> 	<%=DB_FIELDS[1]%>
> </c:set>
> <c:out value="${db_fields_1}"/><br>
> When trying to use the following code:
> <c:set var="db_fields">
> 	<%=DB_FIELDS%>
> </c:set>
> <c:out value="${db_fields[1]}"/><br>

This is not how you pass parameters from scriptlets to EL.  EL typically 
uses pageContext/request/session/application attributes.  To make 
anything but a String accessible via EL, you'll want to do 
pageContext.setAttribute("db_fields", DB_FIELDS), or something like that.

By using the <c:set> tag, you are printing <%=DB_FIELDS%> and then 
storing that as a page context attribute.  In your example, try <c:out 
value="${db_fields}" /> and you'll see what happens if you do 

Serge Knystautas
Lokitech >> software . strategy . design >>
p. 301.656.5501

View raw message