How to get value from a java map using key in a jsp, but key is a javascript value -


i have jsp page , in page hash map request attribute , want extract value specific key . key availble on jsp . how can extarct value map using key?

i solved problem converting java map java script associative array , fetch value array. share code :

<% map<string,string> currencycodemap = (map<string,string>)application.getattribute("currprecisioncodemap");  %>  <script language="javascript">           var map = new array();         <%         (map.entry<string, string> entry : currencycodemap.entryset()) {%>                 map['<%=entry.getkey()%>'] = '<%=entry.getvalue()%>';         <%}         %>  var currencycode = document.accform.currencyname.options[document.accform.currencyname.selectedindex].text;     alert(map[currencycode ]);// gives value  </script> 

above code working fine can provide better solution??

if understand question right, have init hashmap in jsp using , using jstl u can iterate it.

<jsp:usebean id="hm" type="java.util.hashtable<java.lang.long, java.util.arraylist<java.lang.string>>" scope="request"/>  <c:foreach items="${hm[key]}" var="item">     <c:out value="${item.value}" /> </c:foreach> 

also, can next:

pagecontext.setattribute("key", your_key); 

and using in jstl:

${your_key} 

Comments