title: how to receive json response from spring controller to a jsp page
body: <p>I have created one JSP page, with some some text fields. On click of submit button, it calls Ajax call to post the data to Spring controller. Now after saving the data in database, controller creates a JSON response. I want this response to be available on JSP file. below are the code of my files...</p>
  
  <p>JSP file:</p>
  
  <pre class="lang-js prettyprint-override"><code>$(document).ready(function(){
          $("#submitButton").click(function(e){
               var formData = getFormData();
               $.ajax({
                  type: 'POST', 
                  'url': 'http://localhost:8080/Test_ReportingUI/addDb.htm',
                  data: {jsonData: JSON.stringify(formData)},
                  dataType: 'json',
                  success: function(response){ 
                      try{
                          var strResponse=jQuery.parseJSON(response);
                      }catch(err){}
                      if(response.status=='ok')
                      {
                          alert("details added");
                      }
                      else
                      {
                          alert("error happened");
                      }
  
                  },
                  timeout: 10000,
                  error: function(xhr, status, err){ 
                      if(status=='timeout')
                      {   
                          alert('Request time has been out','');
                      }
                      console.log(status,err); 
                  }
              }); 
           });
      });
  </code></pre>
  
  <p>spring controller method:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Autowired RWCustomerService rwCustomerService;
  @RequestMapping (value="addDb.htm", method=RequestMethod.POST)
  String  addEditCustomer(@RequestParam String jsonData)
  {
      System.out.println("hello world");
      System.out.println("-----------------\n"+jsonData);
      ModelAndView modelAndView=new ModelAndView("custDB_setup");
      JSONObject jsonResponse = new JSONObject();
      try{
          JSONObject requestedJSONObject = new JSONObject(jsonData);  
          String dbName = requestedJSONObject.getString("dbName");
          String dbUserName = requestedJSONObject.getString("dbUserName");
          String dbPassword = requestedJSONObject.getString("dbPassword");
          Iterator it=requestedJSONObject.keys();
          while(it.hasNext()){
              System.out.println("Oo..: "+it.next());
          }
          RWReportCustomerDB rwReportCustomerDB = new RWReportCustomerDB();
          rwReportCustomerDB.setDbName(dbName);
          rwReportCustomerDB.setDbLogin(dbUserName);
          rwReportCustomerDB.setDbPassword(dbPassword);
          rwCustomerService.saveDb(rwReportCustomerDB);          
          jsonResponse.put("status", "ok");       
  
      }
      catch(Exception ex){
          ex.printStackTrace();  
      }
      return jsonResponse.toString();
  }
  </code></pre>
  
  <p>data is getting saved in database, therefore json data is reaching the controller method. But, I am unable see the alert box on jsp page i.e. "details added". How can I resolve this issue.</p>