title: Spring MVC validation status 400
body: <p>I have just started learning Spring and stuck with form validation (There is dao/service and all the default set)</p>
  
  <p>I try to make a validation task to prevent inserting into the field more than 3 symbols</p>
  
  <pre><code>@Size (min = 1, max = 3)
  </code></pre>
  
  <p>After that I want to insert the form data to DB and output it on my homepage, when the data satisfies my validation and consists of 1 to 3 symbols, then everything is ok, but when these conditions are not met and I try to insert 4 or more symbols, I receive <code>HTTP STATUS 400</code>. No DB inserts and no view outputs. So I understand that there is validation, however I don't understand why does it show me <code>HTTP STATUS 400</code></p>
  
  <pre><code>@Controller
  public class BookController {
  
      @Autowired
      private BookService bookService;
  
      @RequestMapping(value = "addBook", method = RequestMethod.GET)
      public String addUser(Model model) {
  
          model.addAttribute("user", new ValidationField());
          model.addAttribute("book", new Book());
  
          return "addBook";
      }
  
      @RequestMapping(value = "addBook", method = RequestMethod.POST)
      public String addBook( @ModelAttribute("user") @Valid ValidationField validationField, Book book, BindingResult result) {
          /*this.user(book, result);*/
  
          if (result.hasErrors()) {
              return "addBook";
          }
          this.bookService.addBook(book);
  
          return "redirect:/";
      }
  }
  </code></pre>
  
  <p>Validation Class</p>
  
  <pre><code>public class ValidationField {
  
      @Size(min = 1, max = 3)
      private String name;
  
      @Size(min = 1, max = 3)
      private String genre;
  }
  </code></pre>
  
  <p>and View addBook.jsp</p>
  
  <pre><code>&lt;%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %&gt;
  &lt;%@taglib prefix="t" tagdir="/WEB-INF/tags" %&gt;
  &lt;%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;
  
  &lt;t:tamplate&gt;
    &lt;form:form method="post" action="addBook" commandName="book" modelAttribute="user"&gt;
        &lt;form:errors path="*" cssClass="alert alert-danger" element="div" /&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;form:input path="name"/&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;form:errors path="name"/&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;form:input path="genre" /&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;form:errors path="genre"/&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td colspan="2"&gt; &lt;input type="submit" value="add book"&gt; &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/form:form&gt;
  &lt;/t:tamplate&gt;
  </code></pre>