I want to create a javascript map from a java map to set a dropdown value depending upon the value selected in another dropdown. Below is the code(not working):
var categoryAndReportsMap = new Object();
<%
Map<String,Set<String>> categoryAndReportsJ = (Map<String,Set<String>>) request.getAttribute("categoryAndReports");
for(Map.Entry<String,Set<String>> e : categoryAndReportsJ.entrySet()){ %>
categoryAndReportsMap[ <% e.getKey(); %> ] = <% e.getValue(); %>;
<% } %>
Please suggest how can I achieve this.
:vs=is absolutely not the problem here. The OP just neglected to look at JSP-generated output in webbrowser in order to see the trivial mistake. All those Java variables are namely been printed as JS variable names instead of as JS strings.var asocArray = new Array(); asocArray["a"] = "a";...new Object()instead of anew Array(). This becomes important when you try to iterate the values back out; usingfor...insyntax will net you all of the custom properties as well as "count", etc.