-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>
3
  • Java Servlet and client Javascript live at different times. By the time that Javascript is running, the servlet is done with the page. Commented Sep 25, 2014 at 15:37
  • ok so what can be the solution over this Commented Sep 25, 2014 at 15:38
  • what server / container are you using? Commented Sep 25, 2014 at 16:08

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

thanx i think its the only way to do that... it doesnt solve the issue but it was helpful

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.