tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ely Eshel <...@acm.org>
Subject Arrays in EL
Date Tue, 09 Sep 2003 13:21:08 GMT
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>
I get org.apache.jasper.JasperException: An error occurred while evaluating
custom action attribute "value" with value "${db_fields[1]}": Unable to
find a value for "1" in object of class "java.lang.String" using operator
"[]" (null)
	at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:
254)




Mime
View raw message