AddSpecTwo_form myForm = (AddSpecTwo_form) form;
Collection areaCol = new ArrayList();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {

String areaId = myForm.getAreaId();

System.out.println("areaId=="+areaId);

// 添加语言下拉
String sql = "select * from area";
conn = DBConn.getDBConn();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);

while (rs.next()) {

String areaID = rs.getString("areaId").trim();
String areaName = rs.getString("areaName").trim();
areaCol.add(new LabelValueBean(areaName,areaId));
}

myForm.setAreaIdList(areaCol);
} catch (Exception e) { throw e;
} finally {
DBConn.close(conn);
DBConn.close(stmt); }上面是从数据库表中取出来的数据加到下拉中。为什么加到页面中的下拉,总是显示从数据库表取出的最后一个数据。我如何让他显示默认的选项呢?

解决方案 »

  1.   

    1.从SQL中取出来时,保证默认的在第一个
    2.页面中用程序控制
    <option value="1">默认</option>
    -->
    <option value="1" selected>默认</option>
    3.如果使用了Struts框架和标签的话,就更简单啦
    <html:select name="response" property="customerId">
      <html:optionsCollection name="response" property="customerList"/>
    </html:select>  
    直接在action中设置customerId的值为默认值就OK啦
      

  2.   

    楼上正解,默认是由html里的selected属性控制的