title: Handle Ajax sucess and error in jsp
body: <p>I have Form in JSP which have two input boxes along with submit and clear button like this</p>
  
  <pre><code>&lt;form name="loginForm" method="GET" action="Ajaxexample" id="loginForm"&gt;
   &lt;table&gt;
   &lt;tr&gt;
   &lt;td&gt;From Date&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="n1" value=""/&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr&gt;
   &lt;td&gt;End Date&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="n2" value=""/&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr&gt;&lt;/tr&gt;
   &lt;tr&gt;
   &lt;td&gt;&lt;input type="submit" name="validpro_insert" value="Insert"&gt;&lt;/td&gt;
   &lt;td&gt;&lt;input type="reset" name="validpro_clear" value="Clear"&gt;&lt;/td&gt;
   &lt;/tr&gt;                     
   &lt;/table&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p>As I have called the servlet using get method in form tag which is used to get data from database via JDBC API and to handle the response I have use ajax  like this </p>
  
  <pre><code>  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    
  
           processRequest(request, response);
           System.out.println("In get");
            PrintWriter out = response.getWriter();
            String responseStr = "";
            responseStr = addUser(request); // Return either error/success
            System.out.println("Reponse:" + responseStr);  
             response.setContentType("application/json"); 
             response.setCharacterEncoding("utf-8"); 
             response.getWriter().write(responseStr);
             out.print(responseStr);
  </code></pre>
  
  <p>As I have to write some code to get data from DB in servlet and return that response to ajax which handle success and error on the same jsp like this</p>
  
  <pre><code>&lt;script type="text/javascript" src="js/jq.js"&gt;&lt;/script&gt;   
     &lt;script type="text/javascript"&gt;
  
          var form = $('#loginForm');
          form.submit(function () {
          $.ajax({
          type: form.attr('method'),
          url: form.attr('action'),
          data: form.serialize(),
  
            error: function (theRequest,textStatus, errorThrown) {
                       // Success = false;
                        alert (theRequest.responseText);
                        alert(errorThrown);
                     alert('No graph found');//doesnt goes here
              },
          success: function (data) {
  
                  var result=data;
                  alert(result);
          }     
                  });
                  return false;
              });
          &lt;/script&gt;
  </code></pre>
  
  <p>But the problem is that I am not getting any value from servlet in ajax to handle success or error </p>
  
  <p>I think I am facing this problem due to servlet doget() method code.. if there is any other problem plz let me know. Any help should be appreciated</p>