title: Passing date from jsp to controller in spring
body: <p>I have a form :</p>
  
  <pre><code>&lt;form method="post" action="/addExpense"&gt;
  &lt;input type="text" name="description" required&gt;
  &lt;input type="number" name="amount" required&gt;
  &lt;input type="date" name="created" required&gt;
  &lt;input type="date" name="updated" required&gt;
  &lt;input type="submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and in my controller I have a method :</p>
  
  <pre><code>@RequestMapping(value = "addExpense", method = RequestMethod.POST)
  @ResponseBody
  public String addExpense(@ModelAttribute("expenseDetailDTO") ExpenseDetailDTO expenseDetailDTO) {
      expenseService.addExpense(expenseDetailDTO);
      return "true";
  }
  </code></pre>
  
  <p>ExpenseDetailDTO contents :</p>
  
  <pre><code>public class ExpenseDetailDTO {
  String description;
  Long amount;
  Date created;
  Date updated;
  ...
  }
  </code></pre>
  
  <p>when I submit the form in throws 400 Bad Request. When checking the form data in the chrome dev tools it shows :</p>
  
  <pre><code>description:description
  amount:500
  created:2016-01-01
  updated:2016-01-01
  </code></pre>
  
  <p>I think Spring is not able to convert the Date from form in java.util.Date.</p>
  
  <p>How can I pass date to controller?</p>
  
  <p>EDIT : </p>
  
  <p>Added the annotation for DateTimeFormat :</p>
  
  <pre><code>public class ExpenseDetailDTO {
  String description;
  Long amount;
  @DateTimeFormat(pattern = "yyyy-MM-dd")
  Date created;
  @DateTimeFormat(pattern = "yyyy-MM-dd")
  Date updated;
  ....
  }
  </code></pre>
  
  <p>Still giving 400 Bad Request.</p>