title: Error when using AJAX whit response.getWriter()
body: <p>Hello and thank for your time. I have a problem with my response.getWriter.write</p>
  
  <p>Here is my jsp code </p>
  
  <p>enter code here</p>
  
  <pre><code>  &lt;script&gt;
       $(document).ready(function() {
      var form = $('#form-registrazione');
              form.submit(function ()  {
                  $.ajax({
                      type:'post',
                      url: 'utente',
                      data: form.serialize(),
                      success:function (data) {
                          var result = data;
                          if(result == "usernameEsistente"){
                              alert("IL PENE");
                              $('#errore').html("NON VA BENE");
                          }
                          if(result == "vabene"){
                              window.location.replace("/index.jsp");
                          }
                      }
                  });
              }
          }   
      &lt;/script&gt;
  </code></pre>
  
  <p>and in my servlet "utente" I have this code portion: </p>
  
  <pre><code>            if(model.checkUsername(username)){
                      Utente utente = new Utente();
                      utente.setUser(username);
                      utente.setPass(password);
                      utente.setTipo("Cliente");
  
                      model.doSaveNewAccount(utente); 
                      response.getWriter().write("vabene");
                  }
                  else{
                      response.getWriter().write("usernameEsistente");
                  }
  </code></pre>
  
  <p>the problem is, the response.getWriter().write() overwrite the whole page
  <a href="https://imgur.com/a/D5M8r" rel="nofollow noreferrer">http://imgur.com/a/D5M8r</a></p>
  
  <p>I don't understand why it stays in the servlet page, and does not return in the jsp page where ajax is.</p>