Doing it all in a JSP:
<jsp:useBean id="foo" class="java.util.HashMap"/>
<c:set target="${foo}" property="bar" value="xyzzy"/>
<c:set target="${foo}" property="baz" value="plugh"/>
<c:set var="indexStr" value="bar"/>
<c:out value="${foo[indexStr]}"/>
Outputs "xyzzy". If you're trying to use a scripting variable with JSTL, it
won't work (unless you're using the RT versions of the tags). The EL versions of
the tags only deal with scoped attributes. So, it would work if you did:
request.setAttribute("indexStr", "bar");
Quoting Matthew Van Horn <[EMAIL PROTECTED]>:
>
> How do you write an index variable in an expression, where the index is
> also variable.
> i.e.
> Given:
> HashMap foo = new HashMap();
> foo.put("bar", "xyzzy");
> foo.put("baz", "plugh");
>
> String indexStr = "bar";
>
>
> this doesn't seem to work.
> <c:out value="${ foo[indexStr] }"/>
> I think it is doing foo.get("indexStr") instead of foo.get("bar");
>
>
> How can I do this the right way?
>
> Thanks,
> Matt
--
Kris Schneider <mailto:[EMAIL PROTECTED]>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]