title: sending Json from servlet to javascript
body: <p>I am trying to send an json object array from a servlet to javascript .where I all get the array and parse .
  my ajax call the servlet appropriately but unable to recieve the json array at the javascript end
  please help</p>
  
  <pre><code>public void doPost(HttpServletRequest request, HttpServletResponse response)
          throws IOException {
      System.out.println("Post!!");
      response.setContentType("application/json");//since sendign jsonArray toString
      PrintWriter out = response.getWriter();
      try {
          Marker marker=new Marker( 40.72318,-74.03605);//
  
          JSONArray arrayObj=new JSONArray(); 
          arrayObj.add(marker);
          System.out.println(marker.toString());
          out.print(arrayObj);
  
      } finally {
          out.flush();
          out.close();
      }       
  </code></pre>
  
  <p>}</p>
  
  <p>This is my ajax call in javascript where I am trying to get the json object array form the servlet.</p>
  
  <pre><code>  $.ajax({
            url:'test',
            dataType:'json',
            type:'POST',
            success:function(data){
  
              &lt;%System.out.println(" success");%&gt;
            console.log(data);
            alert('got json hopefully');
            alert(data);
            //
        },
        error:function(jxhr){
            &lt;%System.out.println(" faliure");%&gt;
          console.log(jxhr.responseText);
        }
  
  }); 
  </code></pre>