JSP+JavaScript+JavaBenカスケードメニュー
9738 ワード
index.jsp
<%@page contentType="text/html; charset=gbk" language="java" import="java.sql.*" errorPage=""%>
<jsp:useBean id="connDB" class="com.core.ConnDB" scope="page"/>
<%
ResultSet rs_city = null;
ResultSet rs_Town = null;
ResultSet rs_province = null;
String sql = "";
String sql_T = "";
int SelectID_C = 0;
int SelectID_P=0;
String strCityID1=request.getParameter("CityID");
String strSelectID_P=request.getParameter("ProvinceID");
if (strSelectID_P!=null &&!strSelectID_P.equals("")) {
session.setAttribute("SelectID_P", strSelectID_P);
}
String sql_P = "SELECT * FROM tb_Area WHERE TypeID=1 or TypeID=4 or TypeID=5";
try {
rs_province = connDB.executeQuery(sql_P);
if (rs_province.next()) {
if(session.getAttribute("SelectID_P")!=null){
SelectID_P= Integer.parseInt((String)session.getAttribute("SelectID_P"));
}else{
SelectID_P=rs_province.getInt("ID");
}
%>
<html>
<head>
<title> </title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<link href="style.css" rel="stylesheet">
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
background-image: url(Images/bg.gif);
}
.style1 {color: #FFFFFF}
.style2 {color: #a2bcc5}
-->
</style>
</head>
<script language="javascript">
function ChangeItem_P(){
var ProvinceID=form1.Province.value;
window.location.href="index.jsp?ProvinceID="+ProvinceID;
}
</script>
<script language="javascript">
function ChangeItem_C(){
var CityID=form1.city.value;
window.location.href="index.jsp?CityID="+CityID;
}
</script>
<body>
<table width="400" height="242" border="0" cellpadding="-2" cellspacing="-2" background="Images/add.gif">
<tr>
<td valign="top">
<table width="400" height="271" cellpadding="-2" cellspacing="-2">
<tr>
<td width="11" height="85"> </td>
<td width="373"> </td>
<td width="14">
<span class="style2"></span>
</td>
</tr>
<tr>
<td height="144"> </td>
<td valign="top">
<div align="center">
<form name="form1" method="post" action="">
<table width="88%" height="142" border="1" cellpadding="-2" cellspacing="-2" bordercolor="#669999" bordercolordark="#FFFFFF">
<tr>
<td width="32%" height="27" bgcolor="#809EA4">
<div align="center" class="style1"> :</div>
</td>
<td width="68%">
<%
sql = "select* from tb_area where TypeID=2 and father=" + SelectID_P + "";
sql_T = "select* from tb_area where TypeID=3 and father=" + SelectID_P + "";
rs_city = connDB.executeQuery(sql);
rs_Town = connDB.executeQuery(sql_T);
%>
<div align="left">
<select name="Province" onChange="ChangeItem_P()">
<%
rs_province.first();
do {
%>
<option value="<%=rs_province.getInt("ID")%>" <%if(rs_province.getInt("ID")==SelectID_P){out.print("selected");} %>><%=rs_province.getString("Name")%> </option>
<%
} while (rs_province.next()) ;
%>
</select>
</div>
</td>
</tr>
<tr>
<td height="27" bgcolor="#809EA4">
<div align="center" class="style1"> / :</div>
</td>
<td>
<div align="left">
<%if (rs_city.next()) {
if (strCityID1==null) {
SelectID_C=rs_city.getInt("ID");
}else{
SelectID_C = Integer.parseInt(request.getParameter("CityID"));
}
%>
<select name="city" onChange="ChangeItem_C()">
<%rs_city.first();
do {
%>
<option value="<%=rs_city.getInt("ID")%>" <%if(rs_city.getInt("ID")==SelectID_C){%>selected<%}%>><%=rs_city.getString("Name")%> </option>
<%
} while (rs_city.next());
%>
</select>
</div>
<%} else { %>
<select name="city" onChange="ChangeItem_C()">
<option value="0">---</option>
</select>
</div>
<%
}
%>
</td>
</tr>
<tr>
<td height="27" bgcolor="#809EA4">
<div align="center" class="style1"> / / :</div>
</td>
<td>
<%
if (SelectID_C != 0) { //
sql_T = "select* from tb_area where father=" + SelectID_C + "";
System.out.println("sql_T!=0:"+sql_T);
rs_Town = connDB.executeQuery(sql_T);
}
%>
<%if (rs_Town.next()) {%>
<div align="left">
<select name="town" id="select5">
<%rs_Town.first();
do { %>
<option value="<%=rs_Town.getInt("ID")%>"><%=rs_Town.getString("Name")%></option>
<%
} while (rs_Town.next());
%>
</select>
</div>
<%} else { %>
<div align="left">
<select name="town" id="select5">
<option value="0">---</option>
</select>
</div>
<%} %>
</td>
</tr>
<tr>
<td height="33" colspan="2">
<div align="center">
<input name="Submit" type="submit" class="Style_button" value=" ">
<input name="Button" type="button" class="Style_button" value=" " onClick="javascrip:window.close()">
</div>
</td>
</tr>
</table>
</form>
</div>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<%
}
} catch (Exception e) {
System.out.println(" :"+e.getMessage());
}
%>