<!-- show_select.jsp -->
< contentType="text/html; charset=UTF-8" language="java" import="java.sql.*" import="java.util.*" import="java.io.*" import ="include.my_db.*,java.text.*"%>
<%my_db my_conn=new my_db();%>
<html><body>
<script type="text/javascript" src="../javascript/jquery.js"></script>
<script type="text/javascript">
$(function(){
$('#province').change(function(){
$.get('get_cities.jsp',{province_id: $('#province').val(), random:Math.random()},function(data){
$('#cities').html(data);
});
$('#province').doChange();
});
});
</script>
<select id="province" name="province">
<option value="" selected="true">请选择省份</option>
<%
String sql_query_provinces = "select * from table_provinces";
ResultSet rs_provinces = my_conn.executeQuery(sql_query_provinces);
while(rs_provinces.next()){
%>
<option value="<%=rs_customers.getString("province_id")%>"><%=rs_customers.getString("province_name")%></option>
<%
}
rs_provinces.close();
my_conn.close();%>
</select><br><br>
<select id="cities" name="cities">
<option value="" selected="true">请选择城市</option>
</select>
</body></html>
<!----------------------------->
<!-- get_cities.jsp -->
< contentType="text/html; charset=UTF-8" language="java" import="java.sql.*" import="java.util.*" import="java.io.*" import ="include.my_db.*,java.text.*"%>
<%my_db my_conn=new my_db();%>
<%
String province_id = request.getParameter("province_id");
String cities = "<option value='' selected='true'>请选择城市</option >";
try{
String query = "select * from table_cities where province_id = '"+province_id+"'";
ResultSet rs_cities = my_conn.executeQuery(query);
while(rs_cities.next()){
cities = cities + "<option value='"+rs_cities.getString("city_id")+"'>"+rsOrders.getString("city_name")+"</option>";
}
rs_cities.close();
my_conn.close();
}catch(Exception ex){ex.printStackTrace();}
out.print(cities);
%>
<!----------------------------->