ajax下拉框省市级联动

目录

  • 效果
  • sql数据
  • 前后台代码实现

效果

  • 初始访问页面

  • 选中省会,自动刷新页面

sql数据

--  省市联动数据CREATE TABLE PROVINCE (PID NUMBER PRIMARY KEY,PNAME VARCHAR(20) NOT NULL
)SELECT * FROM PROVINCEINSERT INTO province VALUES (1, '北京市');
INSERT INTO province VALUES (2, '天津市');
INSERT INTO province VALUES (3, '上海市');
INSERT INTO province VALUES (4, '重庆市');
INSERT INTO province VALUES (5, '河北省');
INSERT INTO province VALUES (6, '山西省');
INSERT INTO province VALUES (7, '台湾省');
INSERT INTO province VALUES (8, '辽宁省');
INSERT INTO province VALUES (9, '吉林省');
INSERT INTO province VALUES (10, '黑龙江省');
INSERT INTO province VALUES (11, '江苏省');
INSERT INTO province VALUES (12, '浙江省');
INSERT INTO province VALUES (13, '安徽省');
INSERT INTO province VALUES (14, '福建省');
INSERT INTO province VALUES (15, '江西省');
INSERT INTO province VALUES (16, '山东省');
INSERT INTO province VALUES (17, '河南省');
INSERT INTO province VALUES (18, '湖北省');
INSERT INTO province VALUES (19, '湖南省');
INSERT INTO province VALUES (20, '广东省');
INSERT INTO province VALUES (21, '甘肃省');
INSERT INTO province VALUES (22, '四川省');
INSERT INTO province VALUES (23, '贵州省');
INSERT INTO province VALUES (24, '海南省');
INSERT INTO province VALUES (25, '云南省');
INSERT INTO province VALUES (26, '青海省');
INSERT INTO province VALUES (27, '陕西省');
INSERT INTO province VALUES (28, '广西壮族自治区');
INSERT INTO province VALUES (29, '西藏自治区');
INSERT INTO province VALUES (30, '宁夏回族自治区');
INSERT INTO province VALUES (31, '新疆维吾尔自治区');
INSERT INTO province VALUES (32, '内蒙古自治区');
INSERT INTO province VALUES (33, '澳门特别行政区');
INSERT INTO province VALUES (34, '香港特别行政区');CREATE TABLE city (
Cid NUMBER NOT NULL primary key,
pId NUMBER NOT NULL,
Cname varchar(100) NOT NULL 
)-- DROP TABLE CITYSELECT * FROM CITY ORDER BY CID ASCSELECT * FROM CITY WHERE PID = 1-- 区
INSERT INTO city VALUES (1, 1, '北京市');
INSERT INTO city VALUES (2, 2, '天津市');
INSERT INTO city VALUES (3, 3, '上海市');
INSERT INTO city VALUES (4, 4, '重庆市');
INSERT INTO city VALUES (5, 5, '石家庄市');
INSERT INTO city VALUES (6, 5, '唐山市');
INSERT INTO city VALUES (7, 5, '秦皇岛市');
INSERT INTO city VALUES (8, 5, '邯郸市');
INSERT INTO city VALUES (9, 5, '邢台市');
INSERT INTO city VALUES (10, 5, '保定市');
INSERT INTO city VALUES (11, 5, '张家口市');
INSERT INTO city VALUES (12, 5, '承德市');
INSERT INTO city VALUES (13, 5, '沧州市');
INSERT INTO city VALUES (14, 5, '廊坊市');
INSERT INTO city VALUES (15, 5, '衡水市');
INSERT INTO city VALUES (16, 6, '太原市');
INSERT INTO city VALUES (17, 6, '大同市');
INSERT INTO city VALUES (18, 6, '阳泉市');
INSERT INTO city VALUES (19, 6, '长治市');
INSERT INTO city VALUES (20, 6, '晋城市');
INSERT INTO city VALUES (21, 6, '朔州市');
INSERT INTO city VALUES (22, 6, '晋中市');
INSERT INTO city VALUES (23, 6, '运城市');
INSERT INTO city VALUES (24, 6, '忻州市');
INSERT INTO city VALUES (25, 6, '吕梁市');
INSERT INTO city VALUES (27, 7, '宜兰县');
INSERT INTO city VALUES (36, 7, '南投县');
INSERT INTO city VALUES (42, 7, '云林县');
INSERT INTO city VALUES (43, 7, '嘉义县');
INSERT INTO city VALUES (44, 7, '台南县');
INSERT INTO city VALUES (45, 7, '高雄县');
INSERT INTO city VALUES (46, 7, '屏东县');
INSERT INTO city VALUES (47, 7, '澎湖县');
INSERT INTO city VALUES (48, 7, '台东县');
INSERT INTO city VALUES (49, 7, '花莲县');
INSERT INTO city VALUES (50, 8, '沈阳市');
INSERT INTO city VALUES (51, 8, '大连市');
INSERT INTO city VALUES (52, 8, '鞍山市');
INSERT INTO city VALUES (53, 8, '抚顺市');
INSERT INTO city VALUES (54, 8, '本溪市');
INSERT INTO city VALUES (55, 8, '丹东市');
INSERT INTO city VALUES (56, 8, '锦州市');
INSERT INTO city VALUES (57, 8, '营口市');
INSERT INTO city VALUES (58, 8, '阜新市');
INSERT INTO city VALUES (59, 8, '辽阳市');
INSERT INTO city VALUES (60, 8, '盘锦市');
INSERT INTO city VALUES (61, 8, '铁岭市');
INSERT INTO city VALUES (62, 8, '朝阳市');
INSERT INTO city VALUES (63, 8, '葫芦岛市');
INSERT INTO city VALUES (64, 9, '长春市');
INSERT INTO city VALUES (65, 9, '吉林市');
INSERT INTO city VALUES (66, 9, '四平市');
INSERT INTO city VALUES (67, 9, '辽源市');
INSERT INTO city VALUES (68, 9, '通化市');
INSERT INTO city VALUES (69, 9, '白山市');
INSERT INTO city VALUES (70, 9, '松原市');
INSERT INTO city VALUES (71, 9, '白城市');
INSERT INTO city VALUES (72, 9, '延边朝鲜族自治州');
INSERT INTO city VALUES (73, 10, '哈尔滨市');
INSERT INTO city VALUES (74, 10, '齐齐哈尔市');
INSERT INTO city VALUES (75, 10, '鹤岗市');
INSERT INTO city VALUES (76, 10, '双鸭山市');
INSERT INTO city VALUES (77, 10, '鸡西市');
INSERT INTO city VALUES (78, 10, '大庆市');
INSERT INTO city VALUES (79, 10, '伊春市');
INSERT INTO city VALUES (80, 10, '牡丹江市');
INSERT INTO city VALUES (81, 10, '佳木斯市');
INSERT INTO city VALUES (82, 10, '七台河市');
INSERT INTO city VALUES (83, 10, '黑河市');
INSERT INTO city VALUES (84, 10, '绥化市');
INSERT INTO city VALUES (85, 10, '大兴安岭地区');
INSERT INTO city VALUES (86, 11, '南京市');
INSERT INTO city VALUES (87, 11, '无锡市');
INSERT INTO city VALUES (88, 11, '徐州市');
INSERT INTO city VALUES (89, 11, '常州市');
INSERT INTO city VALUES (90, 11, '苏州市');
INSERT INTO city VALUES (91, 11, '南通市');
INSERT INTO city VALUES (92, 11, '连云港市');
INSERT INTO city VALUES (93, 11, '淮安市');
INSERT INTO city VALUES (94, 11, '盐城市');
INSERT INTO city VALUES (95, 11, '扬州市');
INSERT INTO city VALUES (96, 11, '镇江市');
INSERT INTO city VALUES (97, 11, '泰州市');
INSERT INTO city VALUES (98, 11, '宿迁市');
INSERT INTO city VALUES (99, 12, '杭州市');
INSERT INTO city VALUES (100, 12, '宁波市');
INSERT INTO city VALUES (101, 12, '温州市');
INSERT INTO city VALUES (102, 12, '嘉兴市');
INSERT INTO city VALUES (103, 12, '湖州市');
INSERT INTO city VALUES (104, 12, '绍兴市');
INSERT INTO city VALUES (105, 12, '金华市');
INSERT INTO city VALUES (106, 12, '衢州市');
INSERT INTO city VALUES (107, 12, '舟山市');
INSERT INTO city VALUES (108, 12, '台州市');
INSERT INTO city VALUES (109, 12, '丽水市');
INSERT INTO city VALUES (110, 13, '合肥市');
INSERT INTO city VALUES (111, 13, '芜湖市');
INSERT INTO city VALUES (112, 13, '蚌埠市');
INSERT INTO city VALUES (113, 13, '淮南市');
INSERT INTO city VALUES (114, 13, '马鞍山市');
INSERT INTO city VALUES (115, 13, '淮北市');
INSERT INTO city VALUES (116, 13, '铜陵市');
INSERT INTO city VALUES (117, 13, '安庆市');
INSERT INTO city VALUES (118, 13, '黄山市');
INSERT INTO city VALUES (119, 13, '滁州市');
INSERT INTO city VALUES (120, 13, '阜阳市');
INSERT INTO city VALUES (121, 13, '宿州市');
INSERT INTO city VALUES (122, 13, '巢湖市');
INSERT INTO city VALUES (123, 13, '六安市');
INSERT INTO city VALUES (124, 13, '亳州市');
INSERT INTO city VALUES (125, 13, '池州市');
INSERT INTO city VALUES (126, 13, '宣城市');
INSERT INTO city VALUES (127, 14, '福州市');
INSERT INTO city VALUES (128, 14, '厦门市');
INSERT INTO city VALUES (129, 14, '莆田市');
INSERT INTO city VALUES (130, 14, '三明市');
INSERT INTO city VALUES (131, 14, '泉州市');
INSERT INTO city VALUES (132, 14, '漳州市');
INSERT INTO city VALUES (133, 14, '南平市');
INSERT INTO city VALUES (134, 14, '龙岩市');
INSERT INTO city VALUES (135, 14, '宁德市');
INSERT INTO city VALUES (136, 15, '南昌市');
INSERT INTO city VALUES (137, 15, '景德镇市');
INSERT INTO city VALUES (138, 15, '萍乡市');
INSERT INTO city VALUES (139, 15, '九江市');
INSERT INTO city VALUES (140, 15, '新余市');
INSERT INTO city VALUES (141, 15, '鹰潭市');
INSERT INTO city VALUES (142, 15, '赣州市');
INSERT INTO city VALUES (143, 15, '吉安市');
INSERT INTO city VALUES (144, 15, '宜春市');
INSERT INTO city VALUES (145, 15, '抚州市');
INSERT INTO city VALUES (146, 15, '上饶市');
INSERT INTO city VALUES (147, 16, '济南市');
INSERT INTO city VALUES (148, 16, '青岛市');
INSERT INTO city VALUES (149, 16, '淄博市');
INSERT INTO city VALUES (150, 16, '枣庄市');
INSERT INTO city VALUES (151, 16, '东营市');
INSERT INTO city VALUES (152, 16, '烟台市');
INSERT INTO city VALUES (153, 16, '潍坊市');
INSERT INTO city VALUES (154, 16, '济宁市');
INSERT INTO city VALUES (155, 16, '泰安市');
INSERT INTO city VALUES (156, 16, '威海市');
INSERT INTO city VALUES (157, 16, '日照市');
INSERT INTO city VALUES (158, 16, '莱芜市');
INSERT INTO city VALUES (159, 16, '临沂市');
INSERT INTO city VALUES (160, 16, '德州市');
INSERT INTO city VALUES (161, 16, '聊城市');
INSERT INTO city VALUES (162, 16, '滨州市');
INSERT INTO city VALUES (163, 16, '菏泽市');
INSERT INTO city VALUES (164, 17, '郑州市');
INSERT INTO city VALUES (165, 17, '开封市');
INSERT INTO city VALUES (166, 17, '洛阳市');
INSERT INTO city VALUES (167, 17, '平顶山市');
INSERT INTO city VALUES (168, 17, '安阳市');
INSERT INTO city VALUES (169, 17, '鹤壁市');
INSERT INTO city VALUES (170, 17, '新乡市');
INSERT INTO city VALUES (171, 17, '焦作市');
INSERT INTO city VALUES (172, 17, '濮阳市');
INSERT INTO city VALUES (173, 17, '许昌市');
INSERT INTO city VALUES (174, 17, '漯河市');
INSERT INTO city VALUES (175, 17, '三门峡市');
INSERT INTO city VALUES (176, 17, '南阳市');
INSERT INTO city VALUES (177, 17, '商丘市');
INSERT INTO city VALUES (178, 17, '信阳市');
INSERT INTO city VALUES (179, 17, '周口市');
INSERT INTO city VALUES (180, 17, '驻马店市');
INSERT INTO city VALUES (181, 17, '济源市');
INSERT INTO city VALUES (182, 18, '武汉市');
INSERT INTO city VALUES (183, 18, '黄石市');
INSERT INTO city VALUES (184, 18, '十堰市');
INSERT INTO city VALUES (185, 18, '荆州市');
INSERT INTO city VALUES (186, 18, '宜昌市');
INSERT INTO city VALUES (187, 18, '襄樊市');
INSERT INTO city VALUES (188, 18, '鄂州市');
INSERT INTO city VALUES (189, 18, '荆门市');
INSERT INTO city VALUES (190, 18, '孝感市');
INSERT INTO city VALUES (191, 18, '黄冈市');
INSERT INTO city VALUES (192, 18, '咸宁市');
INSERT INTO city VALUES (193, 18, '随州市');
INSERT INTO city VALUES (194, 18, '仙桃市');
INSERT INTO city VALUES (195, 18, '天门市');
INSERT INTO city VALUES (196, 18, '潜江市');
INSERT INTO city VALUES (197, 18, '神农架林区');
INSERT INTO city VALUES (198, 18, '恩施土家族苗族自治州');
INSERT INTO city VALUES (199, 19, '长沙市');
INSERT INTO city VALUES (200, 19, '株洲市');
INSERT INTO city VALUES (201, 19, '湘潭市');
INSERT INTO city VALUES (202, 19, '衡阳市');
INSERT INTO city VALUES (203, 19, '邵阳市');
INSERT INTO city VALUES (204, 19, '岳阳市');
INSERT INTO city VALUES (205, 19, '常德市');
INSERT INTO city VALUES (206, 19, '张家界市');
INSERT INTO city VALUES (207, 19, '益阳市');
INSERT INTO city VALUES (208, 19, '郴州市');
INSERT INTO city VALUES (209, 19, '永州市');
INSERT INTO city VALUES (210, 19, '怀化市');
INSERT INTO city VALUES (211, 19, '娄底市');
INSERT INTO city VALUES (212, 19, '湘西土家族苗族自治州');
INSERT INTO city VALUES (213, 20, '广州市');
INSERT INTO city VALUES (214, 20, '深圳市');
INSERT INTO city VALUES (215, 20, '珠海市');
INSERT INTO city VALUES (216, 20, '汕头市');
INSERT INTO city VALUES (217, 20, '韶关市');
INSERT INTO city VALUES (218, 20, '佛山市');
INSERT INTO city VALUES (219, 20, '江门市');
INSERT INTO city VALUES (220, 20, '湛江市');
INSERT INTO city VALUES (221, 20, '茂名市');
INSERT INTO city VALUES (222, 20, '肇庆市');
INSERT INTO city VALUES (223, 20, '惠州市');
INSERT INTO city VALUES (224, 20, '梅州市');
INSERT INTO city VALUES (225, 20, '汕尾市');
INSERT INTO city VALUES (226, 20, '河源市');
INSERT INTO city VALUES (227, 20, '阳江市');
INSERT INTO city VALUES (228, 20, '清远市');
INSERT INTO city VALUES (229, 20, '东莞市');
INSERT INTO city VALUES (230, 20, '中山市');
INSERT INTO city VALUES (231, 20, '潮州市');
INSERT INTO city VALUES (232, 20, '揭阳市');
INSERT INTO city VALUES (233, 20, '云浮市');
INSERT INTO city VALUES (234, 21, '兰州市');
INSERT INTO city VALUES (235, 21, '金昌市');
INSERT INTO city VALUES (236, 21, '白银市');
INSERT INTO city VALUES (237, 21, '天水市');
INSERT INTO city VALUES (238, 21, '嘉峪关市');
INSERT INTO city VALUES (239, 21, '武威市');
INSERT INTO city VALUES (240, 21, '张掖市');
INSERT INTO city VALUES (241, 21, '平凉市');
INSERT INTO city VALUES (242, 21, '酒泉市');
INSERT INTO city VALUES (243, 21, '庆阳市');
INSERT INTO city VALUES (244, 21, '定西市');
INSERT INTO city VALUES (245, 21, '陇南市');
INSERT INTO city VALUES (246, 21, '临夏回族自治州');
INSERT INTO city VALUES (247, 21, '甘南藏族自治州');
INSERT INTO city VALUES (248, 22, '成都市');
INSERT INTO city VALUES (249, 22, '自贡市');
INSERT INTO city VALUES (250, 22, '攀枝花市');
INSERT INTO city VALUES (251, 22, '泸州市');
INSERT INTO city VALUES (252, 22, '德阳市');
INSERT INTO city VALUES (253, 22, '绵阳市');
INSERT INTO city VALUES (254, 22, '广元市');
INSERT INTO city VALUES (255, 22, '遂宁市');
INSERT INTO city VALUES (256, 22, '内江市');
INSERT INTO city VALUES (257, 22, '乐山市');
INSERT INTO city VALUES (258, 22, '南充市');
INSERT INTO city VALUES (259, 22, '眉山市');
INSERT INTO city VALUES (260, 22, '宜宾市');
INSERT INTO city VALUES (261, 22, '广安市');
INSERT INTO city VALUES (262, 22, '达州市');
INSERT INTO city VALUES (263, 22, '雅安市');
INSERT INTO city VALUES (264, 22, '巴中市');
INSERT INTO city VALUES (265, 22, '资阳市');
INSERT INTO city VALUES (266, 22, '阿坝藏族羌族自治州');
INSERT INTO city VALUES (267, 22, '甘孜藏族自治州');
INSERT INTO city VALUES (268, 22, '凉山彝族自治州');
INSERT INTO city VALUES (269, 23, '贵阳市');
INSERT INTO city VALUES (270, 23, '六盘水市');
INSERT INTO city VALUES (271, 23, '遵义市');
INSERT INTO city VALUES (272, 23, '安顺市');
INSERT INTO city VALUES (273, 23, '铜仁地区');
INSERT INTO city VALUES (274, 23, '毕节地区');
INSERT INTO city VALUES (275, 23, '黔西南布依族苗族自治州');
INSERT INTO city VALUES (276, 23, '黔东南苗族侗族自治州');
INSERT INTO city VALUES (277, 23, '黔南布依族苗族自治州');
INSERT INTO city VALUES (278, 24, '海口市');
INSERT INTO city VALUES (279, 24, '三亚市');
INSERT INTO city VALUES (280, 24, '五指山市');
INSERT INTO city VALUES (281, 24, '琼海市');
INSERT INTO city VALUES (282, 24, '儋州市');
INSERT INTO city VALUES (283, 24, '文昌市');
INSERT INTO city VALUES (284, 24, '万宁市');
INSERT INTO city VALUES (285, 24, '东方市');
INSERT INTO city VALUES (286, 24, '澄迈县');
INSERT INTO city VALUES (287, 24, '定安县');
INSERT INTO city VALUES (288, 24, '屯昌县');
INSERT INTO city VALUES (289, 24, '临高县');
INSERT INTO city VALUES (290, 24, '白沙黎族自治县');
INSERT INTO city VALUES (291, 24, '昌江黎族自治县');
INSERT INTO city VALUES (292, 24, '乐东黎族自治县');
INSERT INTO city VALUES (293, 24, '陵水黎族自治县');
INSERT INTO city VALUES (294, 24, '保亭黎族苗族自治县');
INSERT INTO city VALUES (295, 24, '琼中黎族苗族自治县');
INSERT INTO city VALUES (296, 25, '昆明市');
INSERT INTO city VALUES (297, 25, '曲靖市');
INSERT INTO city VALUES (298, 25, '玉溪市');
INSERT INTO city VALUES (299, 25, '保山市');
INSERT INTO city VALUES (300, 25, '昭通市');
INSERT INTO city VALUES (301, 25, '丽江市');
INSERT INTO city VALUES (302, 25, '思茅市');
INSERT INTO city VALUES (303, 25, '临沧市');
INSERT INTO city VALUES (304, 25, '文山壮族苗族自治州');
INSERT INTO city VALUES (305, 25, '红河哈尼族彝族自治州');
INSERT INTO city VALUES (306, 25, '西双版纳傣族自治州');
INSERT INTO city VALUES (307, 25, '楚雄彝族自治州');
INSERT INTO city VALUES (308, 25, '大理白族自治州');
INSERT INTO city VALUES (309, 25, '德宏傣族景颇族自治州');
INSERT INTO city VALUES (310, 25, '怒江傈傈族自治州');
INSERT INTO city VALUES (311, 25, '迪庆藏族自治州');
INSERT INTO city VALUES (312, 26, '西宁市');
INSERT INTO city VALUES (313, 26, '海东地区');
INSERT INTO city VALUES (314, 26, '海北藏族自治州');
INSERT INTO city VALUES (315, 26, '黄南藏族自治州');
INSERT INTO city VALUES (316, 26, '海南藏族自治州');
INSERT INTO city VALUES (317, 26, '果洛藏族自治州');
INSERT INTO city VALUES (318, 26, '玉树藏族自治州');
INSERT INTO city VALUES (319, 26, '海西蒙古族藏族自治州');
INSERT INTO city VALUES (320, 27, '西安市');
INSERT INTO city VALUES (321, 27, '铜川市');
INSERT INTO city VALUES (322, 27, '宝鸡市');
INSERT INTO city VALUES (323, 27, '咸阳市');
INSERT INTO city VALUES (324, 27, '渭南市');
INSERT INTO city VALUES (325, 27, '延安市');
INSERT INTO city VALUES (326, 27, '汉中市');
INSERT INTO city VALUES (327, 27, '榆林市');
INSERT INTO city VALUES (328, 27, '安康市');
INSERT INTO city VALUES (329, 27, '商洛市');
INSERT INTO city VALUES (330, 28, '南宁市');
INSERT INTO city VALUES (331, 28, '柳州市');
INSERT INTO city VALUES (332, 28, '桂林市');
INSERT INTO city VALUES (333, 28, '梧州市');
INSERT INTO city VALUES (334, 28, '北海市');
INSERT INTO city VALUES (335, 28, '防城港市');
INSERT INTO city VALUES (336, 28, '钦州市');
INSERT INTO city VALUES (337, 28, '贵港市');
INSERT INTO city VALUES (338, 28, '玉林市');
INSERT INTO city VALUES (339, 28, '百色市');
INSERT INTO city VALUES (340, 28, '贺州市');
INSERT INTO city VALUES (341, 28, '河池市');
INSERT INTO city VALUES (342, 28, '来宾市');
INSERT INTO city VALUES (343, 28, '崇左市');
INSERT INTO city VALUES (344, 29, '拉萨市');
INSERT INTO city VALUES (345, 29, '那曲地区');
INSERT INTO city VALUES (346, 29, '昌都地区');
INSERT INTO city VALUES (347, 29, '山南地区');
INSERT INTO city VALUES (348, 29, '日喀则地区');
INSERT INTO city VALUES (349, 29, '阿里地区');
INSERT INTO city VALUES (350, 29, '林芝地区');
INSERT INTO city VALUES (351, 30, '银川市');
INSERT INTO city VALUES (352, 30, '石嘴山市');
INSERT INTO city VALUES (353, 30, '吴忠市');
INSERT INTO city VALUES (354, 30, '固原市');
INSERT INTO city VALUES (355, 30, '中卫市');
INSERT INTO city VALUES (356, 31, '乌鲁木齐市');
INSERT INTO city VALUES (357, 31, '克拉玛依市');
INSERT INTO city VALUES (358, 31, '石河子市 ');
INSERT INTO city VALUES (359, 31, '阿拉尔市');
INSERT INTO city VALUES (360, 31, '图木舒克市');
INSERT INTO city VALUES (361, 31, '五家渠市');
INSERT INTO city VALUES (362, 31, '吐鲁番市');
INSERT INTO city VALUES (363, 31, '阿克苏市');
INSERT INTO city VALUES (364, 31, '喀什市');
INSERT INTO city VALUES (365, 31, '哈密市');
INSERT INTO city VALUES (366, 31, '和田市');
INSERT INTO city VALUES (367, 31, '阿图什市');
INSERT INTO city VALUES (368, 31, '库尔勒市');
INSERT INTO city VALUES (369, 31, '昌吉市 ');
INSERT INTO city VALUES (370, 31, '阜康市');
INSERT INTO city VALUES (371, 31, '米泉市');
INSERT INTO city VALUES (372, 31, '博乐市');
INSERT INTO city VALUES (373, 31, '伊宁市');
INSERT INTO city VALUES (374, 31, '奎屯市');
INSERT INTO city VALUES (375, 31, '塔城市');
INSERT INTO city VALUES (376, 31, '乌苏市');
INSERT INTO city VALUES (377, 31, '阿勒泰市');
INSERT INTO city VALUES (378, 32, '呼和浩特市');
INSERT INTO city VALUES (379, 32, '包头市');
INSERT INTO city VALUES (380, 32, '乌海市');
INSERT INTO city VALUES (381, 32, '赤峰市');
INSERT INTO city VALUES (382, 32, '通辽市');
INSERT INTO city VALUES (383, 32, '鄂尔多斯市');
INSERT INTO city VALUES (384, 32, '呼伦贝尔市');
INSERT INTO city VALUES (385, 32, '巴彦淖尔市');
INSERT INTO city VALUES (386, 32, '乌兰察布市');
INSERT INTO city VALUES (387, 32, '锡林郭勒盟');
INSERT INTO city VALUES (388, 32, '兴安盟');
INSERT INTO city VALUES (389, 32, '阿拉善盟');
INSERT INTO city VALUES (390, 33, '澳门特别行政区');
INSERT INTO city VALUES (391, 34, '香港特别行政区');

前后台代码实现

  • 所需工具
dom4j.jar -- 解析xml库
ojdbc6.jar -- 数据库驱动包
  • entity,dao层实现

  • basedao

package dao;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;public class BaseDao {static {try {Class.forName("oracle.jdbc.OracleDriver");} catch (ClassNotFoundException e) {e.printStackTrace();}}public static Connection getConn() throws SQLException {Connection conn = null;String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";conn = DriverManager.getConnection(url, "scott", "scott");return conn;}public static void closeAll(Connection conn, PreparedStatement ps, ResultSet rs) {try {if (rs != null)rs.close();if (ps != null)ps.close();if (conn != null)conn.close();} catch (SQLException e) {e.printStackTrace();}}
}
  • citydao
package dao;import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;import entity.City;public class CityDao {public List<City> queryCityByPid(int pId) {List<City> list = new ArrayList<City>();String sql = "SELECT * FROM CITY WHERE PID = ?";Connection conn = null;PreparedStatement ps = null;ResultSet rs = null;try {conn = BaseDao.getConn();ps = conn.prepareStatement(sql);ps.setInt(1, pId);rs = ps.executeQuery();while (rs.next()) {City city = new City();city.setcId(rs.getInt("cid"));city.setpId(rs.getInt("pid"));city.setcName(rs.getString("cname"));list.add(city);}} catch (SQLException e) {e.printStackTrace();} finally {BaseDao.closeAll(conn, ps, rs);}		return list;}	}
  • provincedao
package dao;import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;import entity.Province;public class ProvinceDao {public List<Province> queryAllProvince() {List<Province> list = new ArrayList<Province>();String sql = "SELECT * FROM PROVINCE";Connection conn = null;PreparedStatement ps = null;ResultSet rs = null;try {conn = BaseDao.getConn();ps = conn.prepareStatement(sql);rs = ps.executeQuery();while (rs.next()) {Province pro = new Province();pro.setpId(rs.getInt("pid"));pro.setpName(rs.getString("pname"));list.add(pro);}} catch (SQLException e) {e.printStackTrace();} finally {BaseDao.closeAll(conn, ps, rs);}		return list;}}
  • servlet
package servlet;import java.io.IOException;
import java.util.List;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;import dao.ProvinceDao;
import entity.Province;public class QueryAllProvince extends HttpServlet {/*** 查询所有省会 加载到下拉框*/private static final long serialVersionUID = 1L;@Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {ProvinceDao dao = new ProvinceDao();List<Province> list = dao.queryAllProvince();Document doc = DocumentHelper.createDocument();// dom4j创建根结点Element root = doc.addElement("ProvinceInfo");for (Province p : list) {// 每个省级结点信息Element provinceRoot = root.addElement("province");provinceRoot.addElement("pId").setText("" + p.getpId());provinceRoot.addElement("pName").setText("" + p.getpName());}// 把内存中创建的xml转成stringString provinceXml = doc.asXML();resp.setContentType("text/xml;charset=utf-8");// 以xml字符串的形式发送到前台resp.getWriter().write(provinceXml);}}
package servlet;import java.io.IOException;
import java.util.List;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;import dao.CityDao;
import entity.City;public class QueryCity extends HttpServlet {/*** 根据省会id查询城市*/private static final long serialVersionUID = 1L;@Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {Integer pId = Integer.parseInt(req.getParameter("pId"));CityDao dao = new CityDao();List<City> list = dao.queryCityByPid(pId);Document doc = DocumentHelper.createDocument();Element root = doc.addElement("cityInfo");for (City city : list) {Element cityRoot = root.addElement("city");cityRoot.addElement("cId").setText(city.getcId() + "");cityRoot.addElement("pId").setText(city.getpId() + "");cityRoot.addElement("cName").setText(city.getcName() + "");}String cityXml = doc.asXML();resp.setContentType("text/xml;charset=utf-8");// 以xml字符串的形式发送到前台resp.getWriter().write(cityXml);		}}
  • 前台页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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 'province_city_linkage.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"><script type="text/javascript">function loadProvince() {var ajax = new XMLHttpRequest();ajax.onreadystatechange = function() {if (ajax.status == 200 && ajax.readyState == 4) {// 拿到下拉框var proSelect = document.getElementById("province");// servlet响应的xml对象var provinceXml = ajax.responseXML;// 获取xml的省会结点var provinceArr = provinceXml.getElementsByTagName("province");for (var i = 0; i < provinceArr.length; i++) {var pId = provinceArr[i].firstChild.firstChild.nodeValue; // 这里取结点根据你的xml结构来取var pName = provinceArr[i].lastChild.firstChild.nodeValue;proSelect.add(new Option(pName, pId));}}};ajax.open("get", "QueryAllProvince", true);ajax.send();}loadProvince();function loadCity(pId) {if (pId == 0)return;var citySelect = document.getElementById("city");citySelect.length = 1;var ajax = new XMLHttpRequest();ajax.onreadystatechange = function() {if (ajax.status == 200 && ajax.readyState == 4) {var cityXml = ajax.responseXML;var cityArr = cityXml.getElementsByTagName("city");for (var i = 0; i < cityArr.length; i++) {var cId = cityArr[i].firstChild.firstChild.nodeValue;var cName = cityArr[i].lastChild.firstChild.nodeValue;// 下拉框值在后, value在前citySelect.add(new Option(cName, cId));}}};ajax.open("get", "QueryCity?pId=" + pId, true);ajax.send();}</script></head><body><select id="province" onchange="loadCity(this.value)"><option value="0">请选择省会</option></select><select id="city"><option value="0">请选择城市</option></select>    </body>
</html>

最原始的方法…

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/420879.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python的with关键字

with语句适用于对资源进行访问的场合&#xff0c;确保不管使用过程中是否发生异常都会执行必要的“清理”操作&#xff0c;释放资源&#xff0c;比如文件使用后自动关闭、线程中锁的自动获取和释放等。with表达式其实是try-finally的简写形式。但是又不是全相同。 ""…

pgm2

MRF 笔记 我们先讨论引入 MRF 的必要性。经典的例子就是四个 r.v.s 连成一个正方形的结构的时候&#xff0c;我们没法通过 BN 获得给定对角线两个 r.v.s 而剩下的条件独立&#xff08;不都是 d-sep&#xff09;&#xff0c;反过来如果希望通过 MRF 刻画某些 BN 也是不可行的&am…

(六)ElasticSearch 6.1.1聚合查询

1 普通类型 1.1 基本操作 1.1.1 导入实战数据 数据字段如下&#xff1a; 字段类型作用pricelong汽车售价colortext汽车颜色maketext汽车品牌solddate销售日期 # 创建索引 PUT /cars {"mappings" : {"transactions" : {"properties" : {"…

12 Essential Bootstrap Tools for Web Designers

12 Essential Bootstrap Tools for Web Designers Posted by vikas on June 6, 2014, filed in: Tools, Web Design 原文地址&#xff1a;http://designzum.com/2014/06/06/12-best-bootstrap-tools-for-web-designers/Bootstrap is a great front end website development pla…

Sublime Text3自定义快捷键

转载于:https://www.cnblogs.com/shimily/articles/3783711.html

打jar包和执行jar包

使用eclipse打jar包 默认生成的目录在/Work/Projects/eclipse-workspace 执行 java -cp hellotest.jar com.feiyangedu.sample.Main java -cp testtesttest.jar com.feiyangedu.sample.Person out&#xff1a;print person java -cp testtesttest.jar com.feiyangedu.sample.…

受限波尔兹曼机

1. 概述 前面描述的神经网络模型是一种确定的结构。而波尔兹曼网络是一种随机网络。如何来描述一个随机网络呢&#xff1f;很多书上有大量的篇幅介绍其原理。这里把它总结为以下两点。 第一&#xff0c;概率分布函数。由于网络节点的取值状态是随机的&#xff0c;从贝叶斯网的…

推荐20款基于 jQuery CSS 的文本效果插件

jQuery 和 CSS 可以说是设计和开发行业的一次革命。这一切如此简单&#xff0c;快捷的一站式服务。jQuery 允许你在你的网页中添加一些真正令人惊叹的东西而不用付出很大的努力&#xff0c;要感谢那些优秀的 jQuery 插件。 所以今天我们将展示一些很酷的文本效果插件&#xff0…

王灏:光音网络致力打造Wi-Fi大生态圈

光音网络&#xff0c;做的是本地网络综合服务。在中国&#xff0c;想把互联网做到覆盖延伸范围之外的最后100米&#xff0c;光音网络是当中一家&#xff0c;也是最坚持的一家。为千万家本地生活商户提供帮助&#xff0c;为数亿本地用户提供最佳的本地网络体验&#xff0c;这是光…

Replication--查看未分发命令和预估所需时间

当复制有延迟时&#xff0c;我们可以使用复制监视器来查看各订阅的未分发命令书和预估所需时间&#xff0c;如下图&#xff1a; 但是当分发和订阅数比较多的时候&#xff0c;依次查看比较费时&#xff0c;我们可以使用sys.sp_replmonitorsubscriptionpendingcmds来查看&#xf…

利用反射和xml配置文件手写一个小型的框架

通用的增删改查1. 利用xml配置实体类和数据库表名的映射关系2. 根据xml设计&#xff0c;用正确的数据结构映射类封装好xml信息3. 得到数据库连接前&#xff0c;读取xml信息&#xff0c;用map封装成映射数据4. 写dao时根据反射和map生成sql语句&#xff0c;拿到属性值测试为了解…

DPtoLP/LPtoDP 和 ScreenToClient/ClientToScreen

设备坐标&#xff08;Device Coordinate&#xff09;又称为物理坐标&#xff08;Physical Coordinate&#xff09;&#xff0c;是指输出设备上的坐标。通常将屏幕上的设备坐标称为屏幕坐标。设备坐标用对象距离窗口左上角的水平距离和垂直距离来指定对象的位置&#xff0c;是以…

前端学习(1127):递归求数学题2

斐波那契数列 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>Document</title> </head>…

1008 数组元素循环右移问题 (20分)

输入样例: 6 2 1 2 3 4 5 6 输出样例: 5 6 1 2 3 4 # -*- coding: utf-8 -*- import mathdef right_shift(lst, m):n len(lst)m m % nfor j in range(math.gcd(m, n)):temp lst[j]i jwhile (i - m) % n > j:lst[i] lst[(i - m) % n]i (i - m) % nlst[i] tempretur…