首先
定义函数
public String selLIM(){
String SelString="<option value=\"\">----请选择----</option>";
String sqlStr ="select * from 表名称 t where限制条件";
try{
conn = new ConnDB().getConn();
smt = conn.createStatement();
rs = smt.executeQuery(sqlStr);
List<String> list_name=new ArrayList<String>();
List<String> list_gbid=new ArrayList<String>();
while(rs.next()){
list_name.add(rs.getString("名字"));
list_gbid.add(rs.getString("value值_id"));
}
String[] name = list_name.toArray(new String[list_name.size()]);
String[] value = list_gbid.toArray(new String[list_gbid.size()]);
//获取查询后的行数。
int rowCount=list_name.size();
for(int i =0; i<rowCount; i++){
SelString+="<option value='"+value[i]+"'>"+name[i]+"</option>";
}
}catch(Exception e){
e.printStackTrace();
}
//System.out.print(SelString);
return SelString;
}
初始化:
objthemeDict otd = new objthemeDict();
String limSEL = otd.selLIM();
html中的select框
<td>障碍物类型:</td>
<td><select id="gb12319" οnchange="changeLIM(this.value)" style="width:65%;height:25px"><%=limSEL%></select>
</td>
接着我们定义