Spring MVC form does not bind defined model attributes
<p>I am trying to display the select options on a JSP page. The options are added to the model object, but they are not being displayed, and I can't figure out why. My controller code is given below</p>

<pre><code>  List&lt;String&gt; buildServerEnvironments() {
    List&lt;String&gt; environments = new ArrayList&lt;&gt;();
    environments.add("cert");
    environments.add("qa5"); 
    return environments;
  }

  @RequestMapping(value = "/downloaddcrcontent", method = RequestMethod.GET)
  String showEnvironmentForm(Model model) { 

    model.addAttribute("envObj", new Environment());
    model.addAttribute("serverEnvironments", this.buildServerEnvironments());
    return "environments";
  }
</code></pre>

<p>My model bean is given below:</p>

<pre><code>public class Environment {

    private String environment;

    public String getEnvironment() {
      return environment;
    }

    public void setEnvironment(String environment) {
      this.environment = environment;
    }


    @Override
    public String toString() {
      // TODO Auto-generated method stub
      return new StringBuilder(this.getClass().getSimpleName()).
          append("(environment = ").append(this.environment).append(")").
          toString();
    }
  }
</code></pre>

<p>My JSP page.</p>

<pre><code>&lt;%@ page contentType="text/html;charset=UTF-8" language="java" %&gt;
&lt;%-- Used to import resources. --%&gt;
&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;
&lt;%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%&gt;
&lt;%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
   &lt;head&gt;
      &lt;title&gt;Select Environment&lt;/title&gt;
      &lt;%@ include file="meta_head.jspf" %&gt;
      &lt;%@ include file="bootstrap_import.jspf" %&gt;
      &lt;!--  Custom style sheet.  --&gt;
      &lt;style&gt;
      body {
         padding-top: 50px;
         padding-bottom: 50px;
         background-color: #EEE;
      }

      .form-signin {
        max-width: 330px;
        padding: 15px;
        margin: 0 auto;
      }
      &lt;/style&gt;

   &lt;/head&gt;
   &lt;body&gt;
      &lt;div class="container"&gt;
      &lt;div class="row"&gt;
      &lt;div class="form-signin"&gt;
        &lt;p class="lead"&gt;Environment Selection.&lt;/p&gt;
        &lt;form:form class="form-signin form-horizontal" method="POST" action="generatedcrreport" modelAttribute="envObj" &gt;

           &lt;spring:bind path="environment"&gt;
           &lt;div class="form-group ${status.error ? 'has-error' : ''}"&gt;
              &lt;form:label path="environment"&gt;Environment&lt;/form:label&gt;
                &lt;c:out value="${serverEnvironments}" /&gt;
                &lt;form:select path="environment" class="form-control" tabindex="0"&gt;
                   &lt;form:option value=""&gt;Select an environment&lt;/form:option&gt;
                   &lt;c:forEach var="env" items="${serverEnvironments}" varStatus="index"&gt;
                      &lt;form:option value="${env}"&gt;&lt;c:out value="${env}" /&gt;&lt;/form:option&gt;
                   &lt;/c:forEach&gt;
                &lt;/form:select&gt;
           &lt;/spring:bind&gt;


           &lt;/div&gt;

    &lt;form:button type="submit" class="btn btn-lg btn-primary btn-block"&gt;Select Environment&lt;/form:button&gt;
  &lt;/form:form&gt;
  &lt;/div&gt;

      &lt;/div&gt;

    &lt;/div&gt;
   &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>I find that rendered JSP does not recognize the <code>serverEnvironments</code> attribute that I added to the Spring's model object. I have gone through the following posts</p>

<ol>
<li><a href="https://stackoverflow.com/questions/16953131/spring-mvc-model-attribute-value-not-displaying">Spring MVC model attribute value not displaying</a></li>
<li><a href="https://stackoverflow.com/questions/13953266/how-to-bind-multiple-dropdown-to-model-spring-mvc">How to bind multiple dropdown to model - spring mvc</a></li>
<li><a href="https://stackoverflow.com/questions/19997340/how-to-bind-select-option-value-in-spring-mvc">how to bind select option value in spring mvc</a></li>
</ol>

<p>I even tried the passing the object to ModelAndView, but to no avail. My code for handling ModelAndView is given below and is based on this article</p>

<p><a href="https://www.javacodegeeks.com/2013/07/spring-mvc-form-handling-vol-5-select-option-options-tags.html" rel="nofollow noreferrer">https://www.javacodegeeks.com/2013/07/spring-mvc-form-handling-vol-5-select-option-options-tags.html</a></p>

<pre><code>@RequestMapping(value = "/showEnvironments", method = RequestMethod.GET)
      ModelAndView showEnvironmentForm() { 
       ModelAndView view = new ModelAndView("environments");
        view.addObject("envObj", new Environment());
        view.addObject("serverEnvironments", this.buildServerEnvironments());
        return view;
      }
</code></pre>

<p>I tried displaying the <code>serverAttributes</code> using <code>&lt;c:out value="${serverAttributes}" /&gt;</code> statement, but the output is displayed as it is.</p>

<p>The generated JSP file is:</p>

<p><a href="https://i.stack.imgur.com/6p9RT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6p9RT.png" alt="enter image description here"></a></p>