title: Extrating data from jsp form to controller and saving them to database
body: <p>Hello I am trying to save data from a form to database however I have no idea how to continue now. I have this following code. </p>
  
  <p>I tried using the <code>request.getParameter("id")</code> in the controller which gave me an compiler error. </p>
  
  <p>So how do I get the data from the jsp form to the controller and then save them to the MySQL database ?</p>
  
  <p>jsp file</p>
  
  <pre><code>&lt;%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%&gt;
  &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form action="ProductController" method="post"&gt;
          &lt;p&gt;Enter product name :&lt;/p&gt; &lt;input id="productName" type="text" name="username"&gt; &lt;BR&gt;
          &lt;p&gt;Enter product serial number :&lt;/p&gt; &lt;input id="serialNumber" type="password" name="password"&gt; &lt;BR&gt;
          &lt;input type="submit" placeholder="Submit" /&gt;
      &lt;/form&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The controller </p>
  
  <pre><code>@Controller
  @RequestMapping("/product")
  public class ProductController {
  
      @Autowired
      private ProductService productService;
  
      @RequestMapping("/list")
      public ModelAndView list() {
          ModelAndView modelAndView = new ModelAndView("product/list");
          System.out.println("Count:" + productService.getProducts().size());
          modelAndView.addObject("test", "mytest");
          modelAndView.addObject("count", productService.getProducts().size());
          modelAndView.addObject("products", productService.getProducts());
          return modelAndView;
      }
  }
  </code></pre>
  
  <p>and product DAO</p>
  
  <pre><code>@Override
  public void saveProduct(Product product) {
      //persist(product);
  
      Session session = this.sessionFactory.openSession();
      Transaction tx = session.beginTransaction();
      session.persist(product);
      tx.commit();
      session.close();
  }
  </code></pre>