-2

I had searched all other questions but that doesnt solved my problem so i asked that again with the hope to solve this issue.

I want to pass a Servlet-generated Hashmap to a JSP generated page. On this page, the user selects a particular value of the first dropdown, which populates the contents of second dropdown. The keys of the Map are options for the first list, and the values for the second list.

I tried to create the Map in the script and iterate over it using jstl to create a new Map, unsuccessfully.

Here is my jquery code where i am setting:

 $(document).ready(function() {     
//#year is the id of firstdropdown list
$( "#year" ).change(function() {



     var operationFields = {};

     operationFields= populateArray();
     function populateArray(){
             <c:forEach var="entry" items="${requestScope.hmfillweekrange}">
             operationFields['${entry.key}']:'${entry.value}';

             </c:forEach>
             alert("........."+operationFields);
            return operationFields;          
}; 

Here is a part of my jsp showing code for dropdowns:

On selecting a year the week range should change:

<td><select name="year" id="year">
    <c:forEach var="year" items="${arrYear}">
    <option>${year}</option>
        </c:forEach>
            </select></td>
        <td class="tdmain MakeBold">Week</td>

                <td><select name="weekRange" id="wRange" >
                        <c:forEach var="week" items="${arrWeeks}">
                                <option>${week}</option>
                            </c:forEach>
                        </select></td>
kirti
  • 4,499
  • 4
  • 31
  • 60

1 Answers1

2

Two solutions. In both solutions you should convert your Map to JSON. Jackson can do this for you automatically

  1. In your JSP request code, embed the JSON in a script block
  2. Use AJAX from Javascript on your page to request the JSON from a separate JSP / Servlet
ControlAltDel
  • 33,923
  • 10
  • 53
  • 80
  • thanx i think its the only way to do that... it doesnt solve the issue but it was helpful – kirti Sep 26 '14 at 08:29