Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to access Map using a dynamic key?

843838Aug 19 2005 — edited Aug 22 2005
Hello!
I am trying to retrieve data from a hashMap. The key provided in dyanmic. The code is below:
---------------
<%
java.util.HashMap map = new java.util.HashMap();
map.put("key one", "value one");
map.put("key two", "value two");
map.put("key three", "value three");

pageContext.setAttribute("map" , map);

%>
<c:set var="keyVar" value="key one" />

<c:forEach items="${map}" var="mapVar" varStatus="loopStatus">
<p>
<c:out value='${map.($keyVar}}' />
</p>
</c:forEach>
---------------------------
<c:out value='${map.($keyVar}}' /> gives me an error. Please help!

Tia
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 19 2005
Added on Aug 19 2005
4 comments
1,066 views