title: how to get response from servlet for ajax call
body: <p>I had called a servlet using ajax.</p>
  
  <pre><code>        $.ajax({
          type: "post",
          url: "FileUploadServlet", //this is my servlet
          dataType: 'json',
          data:{"myJsonString":"myJsonString","aadhar":"aadhar"},
          //data: "myJsonString" ,
          beforeSend: function (request)
          {
              request.setRequestHeader("myJsonString", myJsonString);
              request.setRequestHeader("aadhar", aadhar);
  
          },
          success: function(response){
              // $('#uidrespon').html(response); 
              //alert(uidrespon);
          } 
          });
  </code></pre>
  
  <p>From my servlet i wanna pass the response to the ajax. For sending the response from the servlet I am using this using code but i am not getting response from through ajax</p>
  
  <pre><code>         protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      response.setContentType("application/json;charset=utf-8");
      PrintWriter out = response.getWriter();
      System.out.println("In doPost");
  
      String stat="";
      String member_Id="111111111";
      String session_id="121233";
  
  
  
      try{
          System.out.println("In try--------");
          String strrs = request.getHeader("myJsonString");
          String uid_val = request.getHeader("aadhar");
          System.out.println("Uid value..."+uid_val);
          if(strrs!= null){
               stat = "Uploaded Successfully";
               System.out.println("upload status"+stat);
          }else if(strrs == null){
              stat = "Uploaded Failed";
               System.out.println("upload status"+stat);
              request.setAttribute("status", stat);
          }   
  
          byte[] b = strrs.getBytes();
          System.out.println("In bytes---"+b);
          String encodedString = Base64.encodeBase64(b).toString();
          System.out.println("In image---\n"+encodedString);
  
           uid_webservice tes = new uid_webservice();
  
           String src= tes.authenticate(member_Id,uid_val,encodedString,session_id);
  
           System.out.println("Source------"+src); // Getting return value value from uid_webservice 
  
           request.setAttribute("uidrespon", src);
  
           response.setContentType("text/plain");  
           response.setCharacterEncoding("UTF-8"); 
           response.getWriter().write(src);
  </code></pre>
  
  <p>Can any one help me out...Thanx in advance</p>