tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ely Eshel <>
Subject RE: Arrays in EL
Date Tue, 09 Sep 2003 14:02:07 GMT

Thanks. The pageContext.setAttribute() works!

-----Original Message-----
From: Serge Knystautas [] 
Sent: Tuesday, September 09, 2003 9:43 AM
To: Tag Libraries Users List
Subject: Re: Arrays in EL

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

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message