jsp中怎样从数据库中提取一项数据生成下拉列表

jsp中怎样从数据库中提取一项数据生成下拉列表,第1张

如果你用的是纯jsp代码可以这样:

<select>

<%

List<Object[]>

list

=

你的查询所有方法

for(int

i

=0i<list.size()i++){

Object

[]

o

=

list.get(i)

%>

<option

value="<%=o[0]

%>"><%=o[1]

%></option>

<%

}

%>

</select>

不到方法在追问

先把数据库里的数据取出来 内容放到选项框里

java

public static String Option(String str,String str_value,String print_str){

String sel ="<option value="+str_value

if(str.equals(str_value))

sel =sel+" selected"

sel =sel+">"+print_str+"</option>"

return sel

}

String sql = "select id, name _from table "

rs = dbo.Query(sql)

String option = ""

while (rs.next()) {

option = option

+ Comfunc.Option('', rs.getString("id"), rs.getString("name"))}

jsp

<% String option=(String)request.getAttribute("optiondept")%>

<select name="sel" style="width:135">

<%=option%>

</select>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/6693340.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-26
下一篇 2023-03-26

发表评论

登录后才能评论

评论列表(0条)

保存