title: Radio button selection and its value in spring mvc
body: <p>I am creating a web application which is based on Spring mvc framework.This application contains four radio buttons.My requirement is to pass the selection of radio buttons to controller that part is done.Now,once the selection is passed to controller then I don't know how to retain the selection of the radio on JSP.Because When I am returning the name of jsp as index.jsp then page is getting reloaded with intial values of no selection in radio button</p>
  
  <pre><code>&lt;form id="envselection" action="${pageContext.request.contextPath}/env" method="post"&gt;
  &lt;input type="radio" name="env" id="radioSelection" value="QA 71" onclick="submitForm()"&gt;
  &lt;input type="radio" name="env" id="radioSelection" value="QA 72" onclick="submitForm()"&gt;
  &lt;input type="radio" name="env" id="radioSelection" value="QA 73" onclick="submitForm()"&gt;
  &lt;input type="radio" name="env" id="radioSelection" value="QA 74" onclick="submitForm()"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Javascript</p>
  
  <pre><code>&lt;script&gt;
  function submitForm() {
      document.getElementById("envselection").submit();
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>Controller part</p>
  
  <pre><code>@RequestMapping(value = "/env", method = RequestMethod.POST)
      public String env(HttpServletRequest request){
  
          logger.info("parameter is "+request.getParameter("env"));
          return "index";
  
      }
  </code></pre>
  
  <p>Is there any other way of setting the selected value of radio button for java use and retaining the selection of radio button on JSP also.</p>
  
  <p>Thanks in advance</p>