关联就是了,一个变化触发另一个变化好像javascript 可以 实现!

解决方案 »

  1.   

    完全可以用JAVASCRIPT来实现,当然你的JAVASCRIPT里面的数组要使用JAVA程序来生成。
      

  2.   

    <%
    DBConnect dbc=null;
    ResultSet rs=null;
    String sql=null;
    String college=request.getParameter("college");
    if(college!=null) college=college.trim();
    String classname=request.getParameter("class_name");
    String order=request.getParameter("order");
    if(order==null)
    order="stucode";
    %>
    <script language="javascript">
    function jump(obj)
    {
    var url="class.jsp?college="+obj.options[obj.selectedIndex].value;
    location.href=url;
    }function jump2(obj)
    {
    var url="class.jsp?college="+form1.college.options[form1.college.options.selectedIndex].value+"&class_name="+obj.value;
    location.href=url;
    }
    </script>
    <%try
    {
    dbc=new DBConnect("user");%>
    <form name="form1" action="post">
    <%
    if(sign!=2)
    {
    %>
    <select name="college" onChange="jump(this)"><%
    if(sign==0)
    sql="select * from college";
    else if(sign==1)
    sql="select * from college where col_code='"+sign_s+"'";
    rs=dbc.executeQuery(sql);
    while(rs.next())
    {
    String code=rs.getString("col_code");
    if(code!=null) code=code.trim();
    String name=rs.getString("col_name").trim();
    if(code!=null&&college==null) college=code;
    if(code.equals(college))
    out.println("<option selected value=\""+code+"\">"+name+"</option>");
    else
    out.println("<option  value=\""+code+"\">"+name+"</option>");}
    %></select>
    <select name="classname" onChange="jump2(this)">
    <option value="" >选择班级</option>
    <%if(sign==0||sign==1)
    sql="select * from class where col_code='"+college+"'";
    if(college!=null) 
    {
    rs=dbc.executeQuery(sql);
    while(rs.next())
    {
    String class_code=rs.getString("ca_code").trim();
    String class_name=rs.getString("ca_name").trim();
    if(classname!=null&&classname.equals(class_code))
    out.println("<option selected value=\""+class_code+"\">"+class_name+"</option>");
    else
    out.println("<option value=\""+class_code+"\">"+class_name+"</option>");
    }
    }
    %>
    </select>
    <%
    }
    %>
    </form>
    </td>
    </tr>
    <tr>
     <td  height=30 colspan=11 valign="middle" bgcolor=#EFEFEF>
     <div align="center">
     <%
      if(classname!=null&&(sign==0||sign==1))
    {
    sql="select * from student WHERE SUBSTRING(xuehao, 1, 5) = '"+classname+"'";
    }
    else 
    {
    sql="select * from student WHERE SUBSTRING(xuehao, 1, 5) = '"+sign_s+"'";
    classname=sign_s;
    }
    if(classname!=null)
    {%>
    <tr height="35" > 
    <td width="5%" height=35><div align="center">学号</div></td>
    <td width="5%" height=35><div align="center">姓名</div></td>
    <td width="2%"><div align="center">性别</div></td>
    <td width="8%"><div align="center">出生日期</div></td>
    <td width="10%"><div align="center">身份证</div></td>
    <td width="8%"><div align="center">省份</div></td>  
         </tr>
    <%
    rs=dbc.executeQuery(sql);
    while(rs.next())
    {
    String xuehao=rs.getString("xuehao");
    String name=rs.getString("name");
    String sex=rs.getString("sex");
    String birthday=rs.getString("birthday");
    String id_card=rs.getString("id_card");
    String province=rs.getString("province");
    if(name==null)
    name="";
    if(sex==null)
    sex="没填写";
    if(birthday==null)
    birthday="没填写";
    if(id_card==null)
    id_card="没填写";
    if(province==null)
    province="没填写";
    %>
    <tr >
    <td width="5%" height=35><div align="center">&nbsp;<%= xuehao %></div></td>
    <td width="5%" height=35><div align="center">&nbsp;<%= name %></div></td>
    <td width="5%"><div align="center">&nbsp;<%= sex %></div></td>
    <td width="5%"><div align="center">&nbsp;<%= birthday %></div></td>
    <td width="10%"><div align="center">&nbsp;<%= id_card %></div></td>
    <td width="8%"><div align="center">&nbsp;<%= province %></div></td>   
         </tr>
    <%
    }
    }
     %>
     </div>
     </td>
     </tr>
    </table>
    <%
    }
    catch(Exception e)
    {
    out.println(e.toString());
    }
    finally
    {
    if(dbc!=null)
    dbc.close();
    }%>