This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Struts and the fly likes HashMap - Get value by passing key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "HashMap - Get value by passing key" Watch "HashMap - Get value by passing key" New topic
Author

HashMap - Get value by passing key

aamchi mumbai
Greenhorn

Joined: Mar 04, 2005
Posts: 19
Hi,

i have hasmap like this

HashMap hm = new HashMap();
hm.put("id", "101");
hm.put("name", "java");

request.setAttribute("data", hm);

now i want use struts tag to display value of ID key. is there any way i can pass KEY and i can get value for that key. i dont wat to iterate.

Thanks in advance
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Struts is smart enough to know when an object implements the Map interface, so all you have to do is give the key value as the property. For example, the following tag will display "java" in your example:

<bean:write name="data" scope="request" property="name" />
[ May 05, 2005: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
aamchi mumbai
Greenhorn

Joined: Mar 04, 2005
Posts: 19
Thank for Help
 
Consider Paul's rocket mass heater.
 
subject: HashMap - Get value by passing key
 
Similar Threads
Enthuware Map question
Hashtable and Hashmap Doubt
getting value from hashmap in JSP using struts tag
HashMap question?
If two different objects have same hashcode, how HashMap will retrieve these two objects?