100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > java jsp下拉列表框_用JSP实现下拉列表框三级联动效果

java jsp下拉列表框_用JSP实现下拉列表框三级联动效果

时间:2020-08-10 01:23:50

相关推荐

java jsp下拉列表框_用JSP实现下拉列表框三级联动效果

一、在数据库数据库中建立三个表

1.city

字段:

districtname,locationid,districtid

2.province

字段:

locationid,locationname

3.village

字段:

villageid,villagename,districtid

二、代码如下:

pageEncoding="gb2312"%>

jsp实现三级联动的下拉列表框效果

Connection conn=null;

Statement stmt=null;

ResultSet rs=null,rs1=null,rs2=null;

String sql;

int count;

int count2;

String drivername="com.microsoft.jdbc.sqlserver.SQLServerDriver";

String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=SJLD";

try{

Class.forName(drivername);

conn=DriverManager.getConnection(url,"sa","");

stmt=conn.createStatement();

sql="select * from city order by locationid asc";

rs=stmt.executeQuery(sql);

}catch(SQLException e){

System.out.println(e.getMessage());

}

%>

var onecount;

onecount=0;

subcat=new Array();

count=0;

while(rs.next()){

%>

subcat[]=new Array("","","");

count = count + 1 ;

}

rs.close();

rs=null;

%>

onecount=;

function changelocation(locationid){

document.myform.smalllocation.length=0;

var locationid=locationid;

var i;

document.myform.smalllocation.options[0]=new Option('==所选城市的地区==','');

for(i=0;i

if (subcat[i][1] == locationid)

{

document.myform.smalllocation.options[document.myform.smalllocation.length] = new Option(subcat[i][0], subcat[i][2]);

}

}

}

sql="select * from village order by districtid asc";

rs2=stmt.executeQuery(sql);

%>

var onecount2;

onecount2=0;

subcat2=new Array();

count2=0;

while(rs2.next()){

%>

subcat2[]=new Array("","","");

count2 = count2 + 1 ;

}

rs2.close();

rs2=null;

%>

onecount2=;

function changelocation2(districtid)

{

document.myform.village.length = 0;

var districtid=districtid;

var j;

document.myform.village.options[0] = new Option('==所选地区的县区==','');

for (j=0;j < onecount2; j++)

{

if (subcat2[j][1] == districtid)

{

document.myform.village.options[document.myform.village.length] = new Option(subcat2[j][0], subcat2[j][2]);

}

}

}

分类:

请选择你所在的省份

sql ="select * from province order by locationname asc";

rs1 = stmt.executeQuery(sql);

while(rs1.next()){

%>

">

rs1.close();

rs1 = null;

conn.close();

conn =null;

%>

==所有地区==

==所有县区==

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。