求帮忙,JSP三维数组做三个级联下拉菜单,麻烦帮忙看看三维数组中哪里出现了错误
用三维数组,做三个级联的下拉菜单,并且是从数据库中读取的数据,我现在已经做出了二维的,三维的修改后,没有运行出来,我将代码贴出来,求各位大神指导一下!!!万分感谢!!!!这个是二维已经做好的:
<%@page contentType="text/html;charset=GBK"%>
<%@page import="*"%>
<%@page import="java.sql.*"%>
<jsp:useBean id="OpDB" class="test.conOracle" scope="page" />
<%
String sql0;
Connection con0=OpDB.getConn();//完成与数据库的连接
Statement stmt0=con0.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs0=null;
try{
%>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>表单</title>
<script type="text/javascript">
<%
sql0="select distinct 学院名称 from 系名称表";
rs0=stmt0.executeQuery (sql0);
rs0.last();
int Ri=rs0.getRow();
if(Ri>0){
//rs0.beforeFirst();
String XYMCA[]=new String[Ri];
%>
var Department1=new Array();
<%
for(int i=0;i<Ri;i++){
rs0.absolute(i+1);
String A1=rs0.getString("学院名称");
XYMCA[i]=A1;
%>
Department1[<%=i%>]="<%=A1%>";
<%
}//for(int i=0;i<Ri;i++){
%>
var Department2=new Array(Department1.length);
<%
for(int i=0;i<Ri;i++){
sql0="select * from 系名称表 where 学院名称='"+XYMCA[i]+"'";
rs0=stmt0.executeQuery (sql0);
rs0.last();
int R1=rs0.getRow();
%>
Department2[<%=i%>]=new Array();
<%
for(int j=0;j<R1;j++){
rs0.absolute(j+1);
String A2=rs0.getString("系名称");
%>
Department2[<%=i%>][<%=j%>]="<%=A2%>";
<%
}//for(int j=0;j<R1;j++)
}
%>
function check(){
var v1=document.f1.班级编码.value;
document.f1.submit();
}
</script>
</head>
<body>
<center>
班级情况数据录入
<form name="f1" method="post" action="save.jsp">
<table border="1" width="100%">
<tr>
<td>学院名称:<span id="span1" name="span1"></span></td>
<td>系名称:<span id="span2" name="span2"></span></td>
<tr><td>班级编码:<input type="text" name="班级编码" size="30"></td></div>
<td>班级名称:<input type="text" name="班级名称" size="30"></td>
</tr>
</table>
<table border="0" width="100%">
<tr><td align="right"><input type="button" value="提交" onclick="check();"></td></tr>
</table>
</form>
</center>
<script type="text/Javascript">
var temp1="";
for(var i=0;i<Department1.length;i++){
temp1=temp1+"<option value='"+Department1[i]+"'>"+Department1[i]+"</option>";
}
temp1="<select name='学院名称' style='width:150px;' onchange='getSelectOp1(this);'>"+temp1+"</select>";
span1.innerHTML=temp1;
temp1="";
for(var i=0;i<Department2[0].length;i++){
temp1=temp1+"<option value='"+Department2[0][i]+"'>"+Department2[0][i]+"</option>";
}
temp1="<select name='系名称' style='width:150px;' onchange='getSelectOp2(this);'>"+temp1+"</select>";
span2.innerHTML=temp1;
function getSelectOp1(x){
var optionX=-1;
var temp1="";
for(var i=0;i<x.options.length;i++){
if(x.options[i].selected){
optionX=i;
}
}
for(var i=0;i<Department2[optionX].length;i++){
temp1=temp1+"<option value='"+Department2[optionX][i]+"'>"+Department2[optionX][i]+"</option>";
}
temp1="<select name='系名称' style='width:150px;' onchange='getSelectOp2(this);'>"+temp1+"</select>";
span2.innerHTML=temp1;
}
function getSelectOp2(x){
var temp1="";
for(var i=0;i<x.options.length;i++){
if(x.options[i].selected){
}
}
}
</script>
</body></html>
<%
}else{
out.print("没有院系数据!");
}//if(Ri>0){
}catch(Exception e){
out.println("读库时发生错误!");
}finally{
con0=null;stmt0=null;rs0=null;
}
%>
下面是三维需要大家帮忙看一下的:(目的希望把学院,系,和班级做成级联关系的下拉菜单)
<%@page contentType="text/html;charset=GBK"%>
<%@page import="*"%>
<%@page import="java.sql.*"%>
<jsp:useBean id="OpDB" class="test.conOracle" scope="page" />
<%
String sql0;
Connection con0=OpDB.getConn();//完成与数据库的连接
Statement stmt0=con0.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs0=null;
try{
%>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>表单</title>
<script type="text/javascript">
<%
sql0="select distinct 学院名称 from 系名称表";
rs0=stmt0.executeQuery (sql0);
rs0.last();
int Ri=rs0.getRow();
if(Ri>0){
String XYMCA[]=new String[Ri];
%>
var Department1=new Array();
<%
for(int i=0;i<Ri;i++){
rs0.absolute(i+1);
String A1=rs0.getString("学院名称");
XYMCA[i]=A1;
%>
Department1[<%=i%>]="<%=A1%>";
<%
}
%>
var Department2=new Array(Department1.length);
<%
for(int i=0;i<Ri;i++){
sql0="select * from 系名称表 where 学院名称='"+XYMCA[i]+"'";
rs0=stmt0.executeQuery (sql0);
rs0.last();
int R1=rs0.getRow();
if(R1>0){
String XMCA[]=new String[R1];
%>
Department2[<%=i%>]=new Array();
<%
for(int j=0;j<R1;j++){
rs0.absolute(j+1);
String A2=rs0.getString("系名称");
XMCA[j]=A2;
%>
Department2[<%=i%>][<%=j%>]="<%=A2%>";
<%
}//for(int j=0;j<R1;j++)
%>
var Department3=new Array(Department1.length);
<%
for(int i=0;i<Ri;i++){
sql0="select * from 系名称表 where 学院名称='"+XYMCA[i]+"'";
rs0=stmt0.executeQuery (sql0);
rs0.last();
int R1=rs0.getRow();
%>
Department3[<%=i%>]=new Array(Department2[i].length);
<%
for(int j=0;j<R1;j++){
sql0="select * from 系名称表 where 系名称='"+XMCA[j]+"'";
rs0=stmt0.executeQuery (sql0);
rs0.last();
int R2=rs0.getRow();
if(R2>0){
String BJMCA[]=new String[R2];
%>
Department3[<%=i%>][<%=j%>]=new Array();
<%
for(int k=0;k<R2;k++){
rs0.absolute(k+1);
String A3=rs0.getString("班级名称");
BJMCA[k]=A3;
%>
Department3[<%=i%>][<%=j%>][<%=k%>]="<%=A3%>";
<%
}//for(int k=0;k<R2;k++)
}//for(int j=0;j<R1;j++)
}// for(int i=0;i<Ri;i++)
%>
%>
function check(){
var v1=document.f1.学号.value;
document.f1.submit();
}
</script>
</head>
<body>
<center>
学生信息录入
<form name="f1" method="post" action="save.jsp">
<table border="1" width="100%">
<tr>
<td>学院名称:<span id="span1" name="span1"></span></td>
<td>系名称:<span id="span2" name="span2"></span></td>
<td>班级名称:<span id="span3" name="span3"></span></td>
</tr>
<tr>
<td>学号:<input type="text" name="学号" size="30"></td>
<td>姓名:<input type="text" name="姓名" size="30"></td>
<td>性别: <input type="radio" name="性别" value="男" checked>男
<input type="radio" name="性别" value="女">女</td>
</tr>
<tr>
<td>年龄:<input type="text" name="年龄" size="3"></td>
<td>电话:<input type="text" name="电话" size="50"></td>
<td>家庭住址:<input type="text" name="家庭住址" size="60"></td>
</tr>
</table>
<table border="0" width="100%">
<tr><td align="right"><input type="button" value="提交" onclick="check();"></td></tr>
</table>
</form>
</center>
<script type="text/Javascript">
var temp1="";
for(var i=0;i<Department1.length;i++){
temp1=temp1+"<option value='"+Department1[i]+"'>"+Department1[i]+"</option>";
}temp1="<select name='学院名称' style='width:150px;' onchange='getSelectOp1(this);'>"+temp1+"</select>";
span1.innerHTML=temp1;
temp1="";
for(var i=0;i<Department2[0].length;i++){
temp1=temp1+"<option value='"+Department2[0][i]+"'>"+Department2[0][i]+"</option>";
}
temp1="<select name='系名称' style='width:150px;' onchange='getSelectOp2(this);'>"+temp1+"</select>";
span2.innerHTML=temp1;
temp1="";
for(var i=0;i<Department3[0][0].length;i++){
temp1=temp1+"<option value='"+Department3[0][0][i]+"'>"+Department3[0][0][i]+"</option>";
}
temp1="<select name='班级名称' style='width:150px;' >"+temp1+"</select>";
span3.innerHTML=temp1;
var optionX=-1;
var optionY=-1;
function getSelectOp1(x){
var optionX=-1;
var temp1="";
for(var i=0;i<x.options.length;i++){
if(x.options[i].selected){
optionX=i;
}
}
for(var i=0;i<Department2[OptionX].length;i++){
temp1=temp1+"<option value='"+Department2[OptionX][i]+"'>"+Department2[OptionX][i]+"</option>";
}
temp1="<select name='系名称' style='width:150px;' onchange='getSelectOp2(this);'>"+temp1+"</select>";
span2.innerHTML=temp1;
}
function getSelectOp2(x){
var temp1="";
for(var i=0;i<x.options.length;i++){
if(x.options[i].selected){
for(var i=0;i<Department2[OptionX].length;i++){
if(Department2[OptionX][i].selected){
var OptionY=i;
for(var i=0;i<Department3[OptionX][OptionY].length;i++){
temp1=temp1+"<option value='"+Department3[OptionX][OptionY][i]+"'>"+Department3[OptionX][OptionY][i]+"</option>";
}
temp1="<select name='班级名称' style='width:150px;' >"+temp1+"</select>";
span3.innerHTML=temp1;
}//if(Department2[OptionX][i].selected)
}//for(var i=0;i<Department2[OptionX].length;i++)
}// if(x.options[i].selected)
}// for(var i=0;i<x.options.length;i++)
}//function getSelectOp2(x)
</script>
</body></html>
<%
}//if(R2>0)
}//if(R1>0)
}else{
out.print("没有院系数据!");
}//if(Ri>0)
}catch(Exception e){
out.println("读库时发生错误!");
}finally{
con0=null;stmt0=null;rs0=null;
}
%>