接着上次的话题,下面的就是学生注册时需要的学院,专业,班级,三层列表,
学院:

     
    
专业:

班级:


学院是上来就应该有的,我们把他放到了LabelValueBean里
public Vector getInstitutes()
    {
        Connection connection = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try
        {
            connection = getConnection();
            pstmt = connection.prepareStatement( "select * from institute" );
            rs = pstmt.executeQuery();
            Vector institutes = new Vector();
            institutes.add( new LabelValueBean( "请选择所在学院", "" ) );
            while ( rs.next() )
            {
                institutes.add( new LabelValueBean(
                        rs.getString( "institute" ), rs.getString( "id" ) ) );
            }
            return institutes;
        }
        catch ( Exception e )
        {
            e.printStackTrace();
        }
        finally
        {
            close( rs );
            close( pstmt );
            close( connection );
        }
        return null;
    }
而当它选择了一个学院后,相应的getDepartments(this.value)的js脚本就该工作了,还是四步
var xmlHttp;
function createXMLHttpRequest()
{
 if (window.XMLHttpRequest) 
 { 
  xmlHttp = new XMLHttpRequest(); 
 }
 else if (window.ActiveXObject) 
 {
  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
}
发出请求
function getDepartments(institute) 
{
 createXMLHttpRequest()
 var url = "ajax.do?institute="+institute+"&method=getDepartments"
 xmlHttp.open("GET",url, true)
 xmlHttp.onreadystatechange = departments
 xmlHttp.send(null)
}
处理响应
function departments()
{
 if (xmlHttp.readyState == 4) 
 {
  if (xmlHttp.status == 200) 
  {
   resText = xmlHttp.responseText
   each = resText.split("|")
   buildSelect( each, document.getElementById("departmentId"), "请选择所在专业");
  }
 }
}
function buildSelect(str,sel,label)
{
 sel.options.length=0;
 sel.options[sel.options.length]=new Option(label,"")
 for(var i=0;i