如何在jsp页面中获取js的变量值
今天做一个jsp页面的多个下拉列表联动的问题,发现无法在java中直接获取js的变量的值,麻烦高手帮忙解决下,谢谢。我的打算是获取js的变量值,之后用java获取字符串,并与js的变量值拼接,得到js中的变量名。下面是一个三个表的联动,因为这个页面后面还有一个5个表联动的,所以打算把那个联动的function作成一个公共模块,可是现在调试不过去,总是说对象不存在。例如,我用java输出之后的结果我想得到subcatstudyYear,可是现在的到的是subcatoper,oper为function获取得参数名,我想获得oper的值studyYear。
源代码如下:
<script lanuage=javascript>
<%
out.println( "var onecountstudyYear; ");//学年
out.println( "var onecountstudyTerm; ");//学期
out.println( "subcatstudyYear = new Array(); ");//学年
out.println( "subcatstudyTerm = new Array(); ");//学期
//获取所有学年信息
String[] strParentStudyYear = dbop.select( "select distinct g.Grade_Name,g.Grade_ID,cb.StudyLength from tbGrade g,tbTerm_Manage t,tbCourse_Begin cb where t.Academic_Year=g.Grade_ID and t.termID=cb.TermID ").split( "; ");
//获取的数据不同记录之间用“;”分割,同一条记录不同字段之间用“,”分割
for(int i=0; i <strParentStudyYear.length; i++){
String[] strChildStudyYear = strParentStudyYear[i].split( ", ");
out.println( "subcatstudyYear[ "+i+ "] = new Array(\ " "+strChildStudyYear[0]+ "\ ",\ " "+strChildStudyYear[2]+ "\ ",\ " "+strChildStudyYear[1]+ "\ "); ");
}
//输出学年总数
out.println( "onecountstudyYear= "+strParentStudyYear.length);
//获取所有学期信息
String[] strParentStudyTerm = dbop.select( "select Term,termID,Academic_Year from tbTerm_Manage ").split( "; ");
for(int i=0; i <strParentStudyTerm.length; i++){
String[] strChildStudyTerm = strParentStudyTerm[i].split( ", ");
out.println( "subcatstudyTerm[ "+i+ "] = new Array(\ " "+strChildStudyTerm[0]+ "\ ",\ " "+strChildStudyTerm[2]+ "\ ",\ " "+strChildStudyTerm[1]+ "\ "); ");
}
//输出学期总数
out.println( "onecountstudyTerm= "+strParentStudyTerm.length);
%>
//级联查询
function changelocation(oper,locationid){
document.myform.Nclassid.length = 0;
var locationid=locationid;
var oper=oper;
var i;
<%out.print( "for (i=0;i < onecount ");%> oper <%out.print( "; i++)\n ");%>
<%out.print( "if (subcat ");%> oper <%out.print( "[i][1] == locationid)\n ");%>
<% out.print( "document.all.toggleDemoTable.all.topbar.all. "+);%> oper <% out.print(+ ".options[document.all.toggleDemoTable.all.topbar.all. ");%> oper <% out.print( ".length] = new Option(subcat ");%> oper <% out.print( "[i][0], subcat ");%> oper <% out.print( "[i][2]);\n "); %>
}
</script>
</head>
<body topmargin= "10 " leftmargin= "10 " ondrag= "return false " >
<table class= "toolBar "