title: Dropdown list not displaying with textfield in form
body: <p>I've written a JSP that has a form and the form contains a dropdown list and a texfield. The dropdown is populated from a mysql database using beans which act as DAOs and DTOs. Problem is the dropdown doesn't display the values from the database but when I remove the textfield from the form and leave only the dropdown, it displays fine. someone knows why? Please let me know what to do. The code for the forms is below:</p>
  
  <p>JSP that works:</p>
  
  <pre><code>&lt;%@ page import="java.util.*" %&gt;
  &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;
  &lt;jsp:useBean id="camp" scope="session" class="p1.campusDao"/&gt;
  &lt;%--
      Document   : addCamp
      Created on : May 20, 2011, 11:28:31 AM
      Author     : ken
  --%&gt;
  
  &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
      "http://www.w3.org/TR/html4/loose.dtd"&gt;
  
  &lt;html&gt;
      &lt;head&gt;
          &lt;style type="text/css"&gt;
              body {
                  background-color:#AFC7C7;
                  padding: 0;
                  margin: 0;
              }
              div.wrapper {
                  margin-left: 10%;
                  margin-right: 10%;
                  background-color:#6D7B8D;
                  height: 607px;
                  padding-top:0px;
                  border: thin solid #000000;
              }
  
              div#image{
                  padding-top:1%;
                  padding-bottom:1%;
              }
              div#adminlogin{
                  width:35%;
                  height:40%;
                  background-color:#AFC7C7;
                  border-width:thin;
                  border-style:solid;
                  border-color:#000000;
                  margin: 0 auto;
                  text-align:left;
                  overflow: hidden;
                  padding: 5px;
              }
  
              hr {
                  height:1px;
                  color:#000000;
                  background-color:#000000;
                  width:99%;
                  margin-left: 0 ;
                  margin-right: auto ;
                  border-style:solid;
              }
  
              .inputtext {
                  width: 250px;
                  height: 30px;
                  Font-Family:Arial;
                  Font-Size:18px
              }
  
          &lt;/style&gt;
  
          &lt;script language="javascript" type="text/javascript"&gt;
              function clearText(field){
  
                  if (field.defaultValue == field.value) field.value = '';
                  else if (field.value == '') field.value = field.defaultValue;
  
              }
  
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div class="wrapper"&gt;
              &lt;div id="image"&gt;
                  &lt;p&gt;
                      &lt;img src="${pageContext.request.contextPath}/images/logo.gif"
                           alt="banner"
                           width=100%
                           height="100"
                           /&gt;&lt;/p&gt;
              &lt;/div&gt;&lt;!--end of image div--&gt;
              &lt;div id=adminlogin &gt;
                  &lt;p style="text-align:center"&gt;Adding Hostel&lt;/p&gt;
                  &lt;hr/&gt;
                  &lt;form id="cam" method="POST" action="${pageContext.request.contextPath}/getHos"&gt;
                      &lt;select name="campuses" size="1" id="camps"&gt;
                          &lt;c:forEach items="${camp.stateList}" var="ca"&gt;
                              &lt;%--&lt;option value="1"&gt;&lt;c:out value="${ca.campnm}"/&gt;&lt;/option&gt;--%&gt;
                              &lt;option&gt;${ca.campnm}&lt;/option&gt;
                          &lt;/c:forEach&gt;
                      &lt;/select&gt;
                      &lt;br&gt;
                      &lt;input type="Submit" name="cmdSub" value="SUBMIT"&gt;
                  &lt;/form&gt;
                  &lt;p STYLE="color : #E41B17;"&gt;${message}&lt;/p&gt;
                  &lt;c:remove var="message" scope="session" /&gt;
  
  
  
              &lt;/div&gt;&lt;%--end of admin login div--%&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>JSP with textfield in form and doesn't display dropdown elements in UI:</p>
  
  <pre><code>&lt;%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%&gt;
  &lt;%@ page import="java.util.*" %&gt;
  &lt;jsp:useBean id="campu" scope="session" class="p1.campusDao"/&gt;
  &lt;%--
      Document   : addCamp
      Created on : May 20, 2011, 11:28:31 AM
      Author     : ken
  --%&gt;
  
  &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
      "http://www.w3.org/TR/html4/loose.dtd"&gt;
  
  &lt;html&gt;
      &lt;head&gt;
          &lt;style type="text/css"&gt;
              body {
                  background-color:#AFC7C7;
                  padding: 0;
                  margin: 0;
              }
              div.wrapper {
                  margin-left: 10%;
                  margin-right: 10%;
                  background-color:#6D7B8D;
                  height: 607px;
                  padding-top:0px;
                  border: thin solid #000000;
              }
  
              div#image{
                  padding-top:1%;
                  padding-bottom:1%;
              }
              div#adminlogin{
                  width:35%;
                  height:40%;
                  background-color:#AFC7C7;
                  border-width:thin;
                  border-style:solid;
                  border-color:#000000;
                  margin: 0 auto;
                  text-align:left;
                  overflow: hidden;
                  padding: 5px;
              }
  
              hr {
                  height:1px;
                  color:#000000;
                  background-color:#000000;
                  width:99%;
                  margin-left: 0 ;
                  margin-right: auto ;
                  border-style:solid;
              }
  
              .inputtext {
                  width: 250px;
                  height: 30px;
                  Font-Family:Arial;
                  Font-Size:18px
              }
  
          &lt;/style&gt;
  
          &lt;script language="javascript" type="text/javascript"&gt;
              function clearText(field){
  
                  if (field.defaultValue == field.value) field.value = '';
                  else if (field.value == '') field.value = field.defaultValue;
  
              }
  
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div class="wrapper"&gt;
              &lt;div id="image"&gt;
                  &lt;p&gt;
                      &lt;img src="${pageContext.request.contextPath}/images/logo.gif"
                           alt="banner"
                           width=100%
                           height="100"
                           /&gt;&lt;/p&gt;
              &lt;/div&gt;&lt;!--end of image div--&gt;
              &lt;div id=adminlogin &gt;
                  &lt;p style="text-align:center"&gt;Adding Hostel&lt;/p&gt;
                  &lt;hr/&gt;
                  &lt;form method=POST id="hostel" action="${pageContext.request.contextPath}/getHos"&gt;
                      &lt;p/&gt;
                      &lt;%--The textfield for hostel name--%&gt;
                      &lt;label&gt;Hostel Name&lt;input type="text" id="hostel"  name="hosNm" value=""/&gt;&lt;/label&gt;&lt;br/&gt;
                      &lt;br/&gt;
                      &lt;label&gt;Campus Name &lt;select name="campuses" size="1" id="hostel"&gt;
                          &lt;c:forEach items="${campu.stateList}" var="cam"&gt;
                              &lt;%--&lt;option value="1"&gt;&lt;c:out value="${cam.campnm}"/&gt;&lt;/option&gt;--%&gt;
                              &lt;option&gt;${cam.campnm}&lt;/option&gt;
                          &lt;/c:forEach&gt;
                          &lt;/select&gt;&lt;/label&gt;
                          &lt;br/&gt;
                          &lt;br/&gt;
                      &lt;input type="submit" value="Add" style="font-size:14pt; margin-left: 158px; height: 30px;"/&gt;
  
                  &lt;/form&gt;
                  &lt;p STYLE="color : #E41B17;"&gt;${message}&lt;/p&gt;
                  &lt;c:remove var="message" scope="session" /&gt;
  
  
  
              &lt;/div&gt;&lt;%--end of admin login div--%&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>