title: Passing Data from JSP to Servlet
body: <p>As described in the title I need to pass data from my JSP page to my servlet.
  I load data out of a database into a form of my JSP page. 
  Now the user should be able to change that data.
  So I have to send the changed data back to my servlet to update my database.
  Therefore I want to use the <code>doPost()</code> method in my servlet</p>
  
  <p>This is my JSP:</p>
  
  <pre><code>&lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt;
  &lt;%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
      &lt;meta http-equiv="content-script-type" content="text/javascript" /&gt;
      &lt;meta http-equiv="content-style-type" content="text/css" /&gt;
      &lt;meta http-equiv="content-language" content="de" /&gt;
  
      &lt;link href="../resources/css/basic.css" type="text/css" rel="stylesheet" /&gt;
  
      &lt;title&gt;Edit Movie&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;div id="wrapper"&gt;
          &lt;h2 id="title"&gt;Edit Person&lt;/h2&gt;
          &lt;br&gt;&lt;/br&gt;
          &lt;br&gt;&lt;/br&gt;
          &lt;form id="1" class="appnitro"  method="post" action=""&gt;                     
              &lt;ul&gt;
                  &lt;li id="li_1" &gt;
                      &lt;label class="description" for="element_1"&gt;Name&lt;/label&gt;
                      &lt;div&gt;
                          &lt;input id="element_1" name="element_1" class="element text large" type="text" maxlength="255" value="${requestScope.person.name}"/&gt; 
                      &lt;/div&gt; 
                  &lt;/li&gt;       
                  &lt;li id="li_2" &gt;
                      &lt;label class="description" for="element_2"&gt;Deparment&lt;/label&gt;
                      &lt;div&gt;
                          &lt;input id="element_2" name="element_2" class="element text large" type="text" maxlength="255" value="${requestScope.person.department}"/&gt; 
                      &lt;/div&gt; 
                  &lt;/li&gt;   
                  &lt;li id="li_3" &gt;
                      &lt;label class="description" for="element_3"&gt;Job&lt;/label&gt;
                      &lt;div&gt;
                          &lt;input id="element_3" name="element_3" class="element text large" type="text" maxlength="255" value="${requestScope.person.job}"/&gt; 
                      &lt;/div&gt; 
                  &lt;/li&gt;       
                  &lt;li id="li_4" &gt;
                      &lt;label class="description" for="element_4"&gt;Biographie&lt;/label&gt;
                      &lt;div&gt;
                          &lt;textarea id="element_4" name="element_4" class="element textarea medium"&gt;${requestScope.person.biography}&lt;/textarea&gt; 
                      &lt;/div&gt; 
                  &lt;/li&gt;
                  &lt;li class="buttons"&gt;
                      &lt;input type="hidden" name="form_id" value="652973" /&gt;
                      &lt;input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" /&gt;
                  &lt;/li&gt;
              &lt;/ul&gt;
          &lt;/form&gt;                 
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And this is my Servlet without the <code>doPost()</code> method:</p>
  
  <pre><code>import java.io.IOException;
  
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import de.hof.university.spj.model.People;
  import de.hof.university.spj.model.PeopleDAO;
  
  public class SinglePersonEditServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;
      private PeopleDAO peopleDao = new PeopleDAO();
  
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
          String name = "id";
          String value = request.getParameter(name);
  
          int id = Integer.parseInt(value);
  
          People people = peopleDao.getPerson(id);
  
          request.setAttribute("person", people);
  
          RequestDispatcher reqDispatcher = request.getRequestDispatcher("../jsp/singlePersonEdit.jsp");
          reqDispatcher.forward(request, response);
      }
  }
  </code></pre>
  
  <p>After the submit button was pressed I want to send the changed 
  data to my servlet so I can store it in my database.</p>