title: java-spring-mvc Form values not getting printed on POST
body: <p>i am new to spring mvc 
  i created a project using SpringTemplateProject and used hibernate in that.</p>
  
  <p>i created a form and on post the values are getting inserted in database but the problem is i am not able to display those values on POST.</p>
  
  <p>here is the code.</p>
  
  <p>//Controller</p>
  
  <pre><code>package com.projects.data;
  
  import java.util.Locale;
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.ui.ModelMap;
  import org.springframework.validation.BindingResult;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  
  import com.projects.data.*;
  
  @Controller
  public class HomeController {
  
  private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
  
  @Autowired
  ServiceImpl service;
  
  
  @RequestMapping(value = "/", method = RequestMethod.GET)        
  public String customer(Locale locale, Model model) {
      logger.info("Welcome home! The client locale is {}.", locale);
      return "home";
  }
  
  @RequestMapping(value = "/customer", method = RequestMethod.POST)
     public String addCustomer(@ModelAttribute("customer") Customer customer,Model model)
  {
      service.addCustomer(customer);
              return "customer/customer";
  }
  }
  </code></pre>
  
  <p>Home.jsp</p>
  
  <pre><code>&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;
  &lt;%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%&gt;
  &lt;%@ page session="false" %&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Home&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;spring:url var="customer" value="/customer"/&gt;
  &lt;form:form action="${customer}" method="post" modelAttribute="customer" commandName="custform"&gt;
  &lt;form:label path="custid"&gt;Id:&lt;/form:label&gt;
  &lt;form:input path="custid"/&gt; &lt;br&gt;
  
  &lt;form:label path="name"&gt;Name:&lt;/form:label&gt;
  &lt;form:input path="name"/&gt; &lt;br&gt;
  
  &lt;form:label path="age"&gt;Age:&lt;/form:label&gt;
  &lt;form:input path="age"/&gt; &lt;br&gt;
  
  &lt;input type="submit" value="Save"/&gt;    
  &lt;/form:form&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>customer.jsp</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Submitted Information&lt;/title&gt;
  &lt;/head&gt;
   &lt;body&gt;
  
  &lt;h2&gt;Submitted Information&lt;/h2&gt;
  &lt;table&gt;
   &lt;tr&gt;
      &lt;td&gt;Customer id&lt;/td&gt;
      &lt;td&gt;${custform.custid}&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr&gt;
      &lt;td&gt;Name&lt;/td&gt;
      &lt;td&gt;${custform.name}&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr&gt;
      &lt;td&gt;Age&lt;/td&gt;
      &lt;td&gt;${custform.age}&lt;/td&gt;
   &lt;/tr&gt;
   &lt;/table&gt; 
   &lt;/body&gt;
   &lt;/html&gt;
  </code></pre>
  
  <p>Data is getting inserted in the database but it is not getting displayed.Please help me resolve this.</p>
  
  <p>I tried using @modelAttribute</p>
  
  <pre><code>model.addAttribute("custid",customer.getCustId());
  model.addAttribute("name", customer.getName());
  model.addAttribute("age", customer.getAge());
  </code></pre>
  
  <p>But this also does not seem to work.</p>
  
  <p>Model Class</p>
  
  <pre><code>package com.projects.data;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name="customer")
  public class Customer {
      @Id
      @Column(name="CUST_ID")
      int custId;
  
      @Column(name="NAME")
      String name;
  
      @Column(name="AGE")
      int age;
  
      public Customer(int custId,String name,int age)
      {
          this.custId=custId;
          this.name=name;
          this.age=age;
      }
  
      //getter and setter methods
  
      public Customer() {
          // TODO Auto-generated constructor stub
      }
  
      public int getCustId() {
          return custId;
      }
      public void setCustId(int custId) {
          this.custId = custId;
      }
      public String getName() {
          return name;
      }
      public void setName(String name) {
          this.name = name;
      }
      public int getAge() {
          return age;
      }
      public void setAge(int age) {
          this.age = age;
      }
  
  }
  </code></pre>