Hello I have build a simple form which should save the data to database however when I submit the form the data is not saved. How would I resolve this ?
form in jsp
<form method="post">
Product Name:<br>
<input type="text" id="productName" name="product name">
<br>
Last name:<br>
<input type="text" id="productSerial" name="serial number">
<input type="submit" value="Submit">
</form>
controller
@RequestMapping(value = "/saveNewContact", method = RequestMethod.POST)
public ModelAndView saveContact(@RequestParam("productName") String productName,@RequestParam("productSerial") int productSerial) {
Product product = new Product();
product.setName(productName);
product.setSerial(productSerial);
ProductDao.saveNewProduct(product);
return new ModelAndView("redirect:/");
}
DAO implementation
public void saveNewProduct(Product product) {
jdbcTemplate = new JdbcTemplate(dataSource);
String sql = "INSERT INTO product (name, serial)"
+ " VALUES (?, ?)";
jdbcTemplate.update(sql, product.getName(), product.getSerial());
}