title: Setting the Dropdown as 'selected' in a JSTL For loop
body: <p>I am basically looping through an Arraylist in a JSP page and I can successfully populate a Dropdown with options.</p>
  
  <pre><code>&lt;select id="perm_bmi_stable" name="perm_bmi_stable" class="col-md-12 form-control"&gt;
      &lt;optgroup label="Stability"&gt;
          &lt;c:forEach items="${versions}" var="version"&gt;
              &lt;option value="${version.versionName}"&gt; ${version.versionName &lt;/option&gt;
          &lt;/c:forEach&gt;
      &lt;/optgroup&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Now I need to set the proper value in the dropdown as <strong>selected</strong> depending on the value of the <strong>version.versionName</strong> value.</p>
  
  <p>The Dropdown contains the following values after the for loop generates them:</p>
  
  <ul>
  <li>1.0</li>
  <li>2.0</li>
  <li>3.0</li>
  <li>4.0</li>
  </ul>
  
  <p>If the value in the version.versionName is for example 2.0, I need the loop to set <strong>2.0</strong> as the dropdown's selected option.</p>
  
  <p>How can I add this if condition to my for loop?</p>
  
  <p><strong>I tried this, But it doesn't work:</strong></p>
  
  <pre><code>&lt;option value="${version.versionName}" &lt;c:if test="${versions[0].versionName == '${version.versionName}'}"&gt; &lt;c:out value="selected=selected"&gt;&lt;/c:out&gt;&lt;/c:if&gt;&gt;${version.versionName}&lt;/option&gt;
  </code></pre>