title: How to get the Radio button selected value in Spring MVC
body: <p>I am developing a web application in Spring MVC. I have a user add form. Two types of users are there, Customer and Staff. User type is selected using radio buttons. According to the user type selected,I want to send the filled data in the form into two tables in the database. Can anybody guide me of how to check the selected radio button and accordingly execute the required query.
  Following is my two radio button jsps</p>
  
  <pre><code>     &lt;label  class="radio-inline"&gt;
         &lt;input type="radio" name="customer" id="customer"  value="customer" checked="checked"/&gt;Customer
       &lt;/label&gt;
       &lt;label  class="radio-inline"&gt;
         &lt;input  type="radio" name="staff"  id="staff" value="staff"/&gt;Staff Member
       &lt;/label&gt;
  </code></pre>
  
  <p>Following is my controller method for the submit of the form. I took the two radio buttons to the controller using @RequestParam annotation. If I could check which radio button is selected inside this controller method, then I can exeute the related functions for each scenario. Could anyone please help me with this...</p>
  
  <pre><code>@RequestMapping(value="/addCustomer",method = RequestMethod.POST)
  public ModelAndView saveOrUpdate(@ModelAttribute("newUser")  User newUser,@RequestParam("customer") String customer,
                                   @RequestParam("staff") String staff,BindingResult validationResult) throws SQLIntegrityConstraintViolationException {
  
      if (validationResult.hasErrors()) {
          new ModelAndView("userAdd", "command", newUser);
      }
  
  if(staff selected){
      boolean usernameUnique=staffRepository.checkUsernameUnique(newUser);
      if(usernameUnique) {
          int i = staffRepository.add(newUser);
          if (i == 0)
              return new ModelAndView(new RedirectView("stangeFailurePage"));
          else {
              return new ModelAndView(new RedirectView("successPage"));
          }
      }else{
          validationResult.rejectValue("username", "error.username.exists", "The username is already in use.");
          new ModelAndView("userAdd", "command", newUser);
      }
   }
   if(customer selected){
    // do whatever related to that
   }
      return new ModelAndView(new RedirectView("add"));
  }
  </code></pre>