title: jsp form send data to servlet without changing page
body: <p>I use jsp+servlets and have a form. How can I send the form data to a servlet (to the doPost() method) without leaving the actual page, that contains the form?</p>
  
  <p>I want to press the button "submit", the data should be sent and I want to still remain on the page with the form. I would rather not use javascript.</p>
  
  <p>I have on <code>http://localhost/myproject/</code></p>
  
  <pre><code>&lt;form action="http://localhost/myproject/anotherpage" method="POST"&gt;
  First Name: &lt;input type="text" name="first_name"&gt;
  &lt;br /&gt;
  Last Name: &lt;input type="text" name="last_name" /&gt;
  &lt;input type="submit" value="Submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>when clicking the submit button i get forwarded to the following page: <code>http://localhost/myproject/anotherpage</code></p>
  
  <p>but I want to stay on</p>
  
  <pre><code>http://localhost/myproject/
  </code></pre>
  
  <p>edit: right now I am going to write </p>
  
  <pre><code>request.getRequestDispatcher("/index.jsp").forward(request, response);
  </code></pre>
  
  <p>in the doPost() method</p>