title: Syntactically incorrect request sent upon submitting form with invalid data in Spring MVC (which uses hibernate Validator)
body: <p>Login form: </p>
  
  <pre><code>&lt;f:form class="form-horizontal" method="post" action="/login"
      commandName="logindata"&gt;
      &lt;fieldset&gt;
          &lt;legend class="text-info"&gt;Login&lt;/legend&gt;
          &lt;div class="control-group"&gt;
              &lt;f:label path="uname" class="control-label" for="uname"&gt;Username&lt;/f:label&gt;
              &lt;div class="controls"&gt;
                  &lt;f:input type="text" path="uname" name="uname" id="uname"
                      placeholder="Username" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="control-group"&gt;
              &lt;f:label path="pwd" class="control-label" for="pwd"&gt;Password&lt;/f:label&gt;
              &lt;div class="controls"&gt;
                  &lt;f:input type="password" path="pwd" name="pwd" id="pwd"
                      placeholder="Password" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="control-group"&gt;
              &lt;div class="controls"&gt;
                  &lt;button type="submit" class="btn" id="login"&gt;
                      Login &lt;i class="icon-chevron-right"&gt;&lt;/i&gt;
                  &lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div id="errormsg" class="alert alert-error"&gt;${message}&lt;/div&gt;
      &lt;/fieldset&gt;
  &lt;/f:form&gt;
  </code></pre>
  
  <p>the loginData class: </p>
  
  <pre><code>package com.demo.forms;
  
  import org.hibernate.validator.constraints.Length;
  import org.hibernate.validator.constraints.NotEmpty;
  
  public class loginData {
      @Length(min=4)
      private String uname; 
  
      @NotEmpty
      private String pwd;
  
      public String getUname() {
          return uname;
      }
      public void setUname(String uname) {
          this.uname = uname;
      }
      public String getPwd() {
          return pwd;
      }
      public void setPwd(String pwd) {
          this.pwd = pwd;
      }
  }
  </code></pre>
  
  <p>Controller methods for showing and submitting the form: (Shows homepage which contains signup form and login form)</p>
  
  <pre><code>@RequestMapping(value = "/", method=RequestMethod.GET)
      public String showHome(Model model)
      {
          loginservice.logout();
          model.addAttribute("logindata", new loginData());
          model.addAttribute("signupdata", new signupData());
          return "home";
      }
  </code></pre>
  
  <p>Method called upon submitting login form: </p>
  
  <pre><code>@RequestMapping(value = "login", method=RequestMethod.POST)
      public String submitloginForm(@Valid loginData logindata, SessionStatus state, Model model, BindingResult result)
      {
              if((loginservice.loggedin()) || (result.hasErrors()))
              {
                  return showHome(model);
              }
              else
              {
                  String uname = logindata.getUname();
                  String pwd = logindata.getPwd();
                  if(loginservice.login(uname, pwd))
                  {
                      model.addAttribute("user",uname);
                      return "redirect:profile";
                  }
                  else
                  {
                      model.addAttribute("message","Invalid Username/Password");
                      return showHome(model);
                  }   
              }   
      }
  </code></pre>
  
  <p><br>
  The login works fine when the data entered is 'valid' (either correct or wrong). However, when it is invalid, for instance, when the password field is empty or the username is less than four characters long, following error is shown: </p>
  
  <pre><code>The request sent by the client was syntactically incorrect.
  </code></pre>
  
  <p>Any idea how this might be fixed?</p>