java下拉框如何实现_JSP下拉框联动如何实现(zt)

两种方案

一个是用JavaScript,一次性将两个select的数据统统取出来,将第二张表的数据放到数组中,通过第一个的change事件来改变,优点,运行速度快,缺点,需编写对应的javascript代码,且无法反映实时数据

第二种方案是每次都提交,进行联动,优点,能反映数据库实时数据信息,无须写javascript,缺点,运行速度相对慢,且需要考虑保存用户的已经填写的其他表单数据

看我的,方便

try{

Connection   con=j.getConnection();

Statement   statement=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

String   sql="select   *   from   table";

ResultSet   r=statement.executeQuery(sql);

while(r.next())

{

%>

>

j.releaseConnection(con);

}catch(SQLException   ee){out.print("数据库连接失败!");}

%>

String   las   =request.getParameter("la");

String   ars   =request.getParameter("ar");

%>

function   yjchang(){

document.form2.la.value=document.form1.la.value;

document.form2.submit();

}

部门:

String   la1=request.getParameter("la");

String   la="";

ResultSet   rs_la=null;

try{

rs_la=user.executeQuery("select   branch_id,name   from   branch");

while(rs_la.next()){

la="";

if(rs_la.getString("branch_id").equals(la1)){

la="selected";

%>

"   >

}else{

la="";

%>

">

}catch(   SQLException   sqle   ){}

catch(   Exception   e   ){}

finally{

try{

user.getClose();

if   (rs_la   !=null){

rs_la.close();

rs_la=null;

}

}catch(   SQLException   sqle   ){}

}

%>

员工:

if(las!=null){

String   ar1=request.getParameter("ar");

String   ar="";

ResultSet   rs_area=null;

try{

rs_area=user.executeQuery("select   ygid,name   from   hyj.area   where   branch_id='"+las+"'");

while(rs_area.next()){

ar="";

if(rs_area.getString("ygid").equals(ar1)){

ar="selected";

%>

"   >

">

}catch(   SQLException   sqle   ){}

catch(   Exception   e   ){}

finally{

try{

user.getClose();

if   (rs_area   !=null){

rs_area.close();

rs_area=null;

}

}catch(   SQLException   sqle   ){}

}

%>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值