title: Bad request error 400 when submitting a form
body: <p>I am getting Error Response 400 when submitting the form. I have a form which was working fine before i added a drop down list which displays gender to the user from DB. The Drop down is displaying the data correctly but when i am submitting the form i am getting an error. This only happened when i added the drop down list.</p>
  
  <p><strong>RegistrationController.java :-</strong></p>
  
  <pre><code>@Controller
  public class RegistrationController {
      final static Logger logger = Logger.getLogger(RegistrationController.class);
      private StaffService staffService;
  
      @Autowired
      private GenderDao genderDao;
  
      @Autowired
      public RegistrationController(StaffService staffService) {
          this.staffService = staffService;
      }
  
      @RequestMapping(method = RequestMethod.GET, value = "/register")
      public String registerStaffPage(Model model) {
          List&lt;Gender&gt; genders = genderDao.findAll();
          Iterator&lt;Gender&gt; genderIterators = genders.iterator();
          Map&lt;Gender, String&gt; genderMap = new LinkedHashMap&lt;Gender, String&gt;();
          while (genderIterators.hasNext()) {
              Gender gender = genderIterators.next();
              genderMap.put(gender, gender.getGender());
          }
          model.addAttribute("gendersMap",genderMap);
          model.addAttribute("staffRegistrationBean", new StaffRegistrationBean());
          return "register";
      }
  
      @RequestMapping(method = RequestMethod.POST, value = "/registerStaff")
      public String registerStaff(@ModelAttribute("staffRegistrationBean") StaffRegistrationBean staffRegistrationBean,
              @Valid StaffRegistrationBean staffRegistrationBeans, Errors errors, Model model) {
          // if (errors.hasErrors())
          // return "register";
          staffService.createStaff(staffRegistrationBean);
          return "RegistrationDone";
      }
  
      @PostConstruct
      public void init() {
          logger.debug("RegistrationController Bean has been Initialized.");
      }
  
      @PreDestroy
      public void destroy() {
          logger.debug("RegistrationController Bean has been Destroyed.");
      }
  }
  </code></pre>
  
  <p><strong>StaffRegistrationBean.java</strong></p>
  
  <pre><code>public class StaffRegistrationBean {
  private String userName;
      private String password;
      private String firstName;
      private String lastName;
      private String email;
      private String Organization;
      private String phoneNo;
      private Gender gender;
      // getter and setter follows
  }
  </code></pre>
  
  <p><strong>regsiter.jsp</strong></p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%&gt;
  &lt;%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%&gt;
  &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&gt;
  &lt;%@ page isELIgnored="false"%&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Registration&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;Registration Form&lt;/h1&gt;
      &lt;form:form id="regForm" modelAttribute="staffRegistrationBean"
          action="registerStaff" method="post"&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;form:label path="userName" cssErrorClass="error"&gt;
                          &lt;spring:message code="userName" /&gt; : 
                      &lt;/form:label&gt; &lt;form:input path="userName" name="username" id="username"
                          cssErrorClass="error" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Gender: &lt;form:select path="gender"&gt;
                          &lt;form:options items="${gendersMap}" /&gt;
                      &lt;/form:select&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;form:label path="organization" cssErrorClass="error"&gt;
                          &lt;spring:message code="organizationName" /&gt; : 
                      &lt;/form:label&gt; &lt;form:input path="organization" name="username" id="organization"
                          cssErrorClass="error" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;form:label path="password" cssErrorClass="error"&gt;
                          &lt;spring:message code="password" /&gt; : 
                      &lt;/form:label&gt; &lt;form:input path="password" name="password" id="password"
                          cssErrorClass="error" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;form:label path="firstName" cssErrorClass="error"&gt;
                          &lt;spring:message code="firstName" /&gt; : 
                      &lt;/form:label&gt; &lt;form:input path="firstName" name="firstname" id="firstname"
                          cssErrorClass="error" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;form:label path="lastName" cssErrorClass="error"&gt;
                          &lt;spring:message code="lastName" /&gt; : 
                      &lt;/form:label&gt; &lt;form:input path="lastName" name="lastname" id="lastname"
                          cssErrorClass="error" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;%-- &lt;tr&gt;
                  &lt;td&gt;&lt;form:label path="gender"&gt;
                          &lt;spring:message code="gender" /&gt; : &lt;/form:label&gt;
                  &lt;td&gt;&lt;form:select path="${gender}"&gt;
                          &lt;form:options items="${genderList}" id="id" itemValue="gender"&gt;
                          &lt;/form:options&gt;
                      &lt;/form:select&gt;&lt;/td&gt;
              &lt;/tr&gt; --%&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;form:label path="email" cssErrorClass="error"&gt;
                          &lt;spring:message code="email" /&gt; : 
                      &lt;/form:label&gt; &lt;form:input path="email" name="email" id="email"
                          cssErrorClass="error" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;form:label path="phoneNo" cssErrorClass="error"&gt;
                          &lt;spring:message code="phoneNo" /&gt; : 
                      &lt;/form:label&gt; &lt;form:input path="phoneNo" name="phoneNo" id="phoneNo"
                          cssErrorClass="error" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="submit" value="register"&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/form:form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>**</p>
  
  <ul>
  <li>Error :-</li>
  </ul>
  
  <p>**</p>
  
  <p>HTTP Status 400 – Bad Request</p>
  
  <p>Type Status Report</p>
  
  <p>Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).</p>
  
  <p>GenderMap is a map that has the model to display on the screen. The key is Gender class and value is the gender description. The user will select a gender which will be referring to an id in the gender table.</p>
  
  <p>The Entire code is available at - <a href="https://github.com/iftekharkhan09/ExpenseCalculator_Nex_Gen/tree/DevBranch" rel="nofollow noreferrer">https://github.com/iftekharkhan09/ExpenseCalculator_Nex_Gen/tree/DevBranch</a> </p>
  
  <p>Go to the URL - localhost:8080/ExpenseCalculator/register</p>
  
  <p>Any help will be highly appreciated.</p>