日期:2014-05-17 浏览次数:20691 次
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="UTF-8" session="true"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <% String SqlQuery="SELECT * FROM binary_system"; Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/zhengshi","root","zky"); Statement sql=conn.createStatement(); ResultSet rs=sql.executeQuery(SqlQuery); %> <script type="text/javascript"> var onecount; onecount=0; subcat = new Array(); <% int count = 0; while(rs.next()){ %> subcat[<%=count%>] = new Array("<%=rs.getString("element1")%>", "<%=rs.getString("element2")%>","<%=rs.getString("phase")%>"); <% count++; } rs.close(); %> onecount=<%=count%>; function select1(locationid) { document.myform.erji.length = 0; var i; for (i=0;i < onecount; i++) { if (subcat[i][0].equals(locationid)) { document.myform.erji.options[document.myform.erji.length] = new Option(subcat[i][1]); } } } </script> <body> <form name="myform" method="post"> 元素1: <select id="yiji" name="yiji" onchange="select1(document.myform.yiji.options [document.myform.yiji.selectedIndex].text);"> <OPTION selected value>==请选一级元素==</OPTION> <% Statement sql2=conn.createStatement(); ResultSet rs2=sql.executeQuery(SqlQuery); while(rs2.next()){ %> <option value=<%=rs2.getString("element1")%>><%=rs2.getString("element1")%></option> <% } %> </select> 元素2:<select id="erji" name="erji" > <OPTION selected value>==请选二级元素==</OPTION> </select> <input type="submit" value="提交"> </form> </body> </html>