title: Returning Hashmap From controller to JSP in Springmvc
body: <p>I have two dropdownlists in Jsp One for state and other for country. As soon as i select country the statelist should be populated automatically with respective lists. But i am getting whole jsp page as response in ajax call.
  My ajax Program:</p>
  
  <pre><code>$("select#country").change(function() {
  var val=$("#country").val();
  alert(val);
  $.ajax({
  url : 'getstates',
  method : 'get',
  contentType: 'application/json',
   data :{
            country : val
          },
  
    success: function (data) {
    alert("Success Response"+ data);
  
    },
  
     error :function()
     {
             alert("error");
      }          
  
     });
  </code></pre>
  
  <p>My controller program</p>
  
  <pre><code> @RequestMapping(value = "/getstates", method = RequestMethod.GET)
   public ModelAndView  showstates(@RequestParam(required = false, value = "") 
       String country,@Valid    @ModelAttribute("employee")Login employee, 
       BindingResult result, Model model) {  
      HashMap&lt;String,String&gt;  stateMap = new HashMap&lt;String,String&gt;();
       //put your logic to add state on basis of country
  
       if (country.equals("UnitedStates")) {
           stateMap.put("Al","Alaska");
           stateMap.put("Tl","Texas");
  
       } else if (country.equals("UnitedKingdom")) {
           stateMap.put("Be","Bedfordshire");
           stateMap.put("Ber","Berkshire");
  
       } else if (country.equals("India")) {
           stateMap.put("Mh","Maharashtra");
           stateMap.put("WB","West Bengal");
           stateMap.put("KR","Karnataka");
           stateMap.put("AP","Andhra Pradesh");
           stateMap.put("TN","Tamil Nadu");
       } 
  
  
       return new ModelAndView("LoginForm","state" ,stateMap);
   }
  </code></pre>
  
  <p>I am using spring form. I need to get only Staemap as respone but i am getting whole jsp page as response.</p>