好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > Ajax實現省市縣三級聯動

Ajax實現省市縣三級聯動

熱門標簽:提高電話機器人接通率 外呼系統api對接 荊州智能電銷機器人 廣西智能外呼系統多少錢 大學校門地圖標注 福建微碼電話機器人 平涼高德地圖標注商戶要收費嗎 銷售電銷機器人詐騙 地圖標注與公司業務關系

本文實例為大家分享了Ajax實現省市縣三級聯動的具體代碼,供大家參考,具體內容如下

首先建立數據庫,如下所示

接口

import java.util.List;
public interface ProvinceDao {
 ListProvince> findAll();
}

import java.util.List;
public interface CityDao {
 ListCity> findCityByPid(int pid);
}

import java.util.List;
public interface AreaDao {
 ListArea> findAreaByCid(int cid);
}

接口實現類

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ProvinceDaoImpl implements ProvinceDao{
 public ListProvince> findAll(){
 Connection conn = DBHelper.getConn();
 ArrayListProvince> provinces = new ArrayListProvince>();
 String sql = "select * from aprovince";
 try {
 PreparedStatement ps = conn.prepareStatement(sql);
 ResultSet rs = ps.executeQuery();
 while (rs.next()){
 Province p = new Province();
 p.setPid(rs.getInt(1));
 p.setPname(rs.getString(2));
 provinces.add(p);
 }
 } catch (SQLException e) {
 e.printStackTrace();
 }
 return provinces;
 }
}

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CityDaoImpl implements CityDao {
 @Override
 public ListCity> findCityByPid(int pid) {
 Connection conn = DBHelper.getConn();

 ArrayListCity> cities = new ArrayList>();

 String sql = "select * from acity where pid=?";

 try {
 PreparedStatement ps = conn.prepareStatement(sql);
 ps.setInt(1,pid);
 ResultSet rs = ps.executeQuery();
 while (rs.next()){
 City city = new City();
 city.setPid(rs.getInt(3));
 city.setCid(rs.getInt(1));
 city.setCname(rs.getString(2));
 cities.add(city);
 }
 } catch (SQLException e) {
 e.printStackTrace();
 }
 return cities;
 }
}

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class AreaDaoImpl implements AreaDao {
 @Override
 public ListArea> findAreaByCid(int cid) {
 Connection conn = DBHelper.getConn();
 ArrayListArea> areas = new ArrayList>();
 String sql = "select * from aarea where cid=?";

 try {
 PreparedStatement ps = conn.prepareStatement(sql);
 ps.setInt(1,cid);
 ResultSet rs = ps.executeQuery();
 while (rs.next()){
 Area area = new Area();
 area.setCid(rs.getInt(3));
 area.setAid(rs.getInt(1));
 area.setAname(rs.getString(2));
 areas.add(area);
 }
 } catch (SQLException e) {
 e.printStackTrace();
 }
 return areas;
 }
}

servlet

package cn.zhc.servlet;

import cn.zhc.dao.Impl.ProvinceDaoImpl;
import cn.zhc.dao.ProvinceDao;
import cn.zhc.domin.Province;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/findAll")
public class FindAll extends HttpServlet {
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 request.setCharacterEncoding("utf-8");
 response.setContentType("text/html;charset=utf-8");

 ProvinceDao provinceDao = new ProvinceDaoImpl();
 ListProvince> lists=provinceDao.findAll();

 response.getWriter().write(JSONObject.toJSONString(lists));
 }
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 this.doPost(request, response);
 }
}

package cn.zhc.servlet;

import cn.zhc.dao.CityDao;
import cn.zhc.dao.Impl.CityDaoImpl;
import cn.zhc.domin.City;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/findCityByPid")
public class FindCityByPid extends HttpServlet {
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 request.setCharacterEncoding("utf-8");
 response.setContentType("text/html;charset=utf-8");

 String pid = request.getParameter("pid");

 CityDao cityDao = new CityDaoImpl();
 ListCity> cityList = cityDao.findCityByPid(Integer.parseInt(pid));

 response.getWriter().write(JSONObject.toJSONString(cityList));
 }

 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 this.doPost(request, response);
 }
}

package cn.zhc.servlet;

import cn.zhc.dao.AreaDao;
import cn.zhc.dao.Impl.AreaDaoImpl;
import cn.zhc.domin.Area;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/findAreaByCid")
public class FindAreaByCid extends HttpServlet {
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 request.setCharacterEncoding("utf-8");
 response.setContentType("text/html;charset=utf-8");

 String cid = request.getParameter("cid");

 AreaDao areaDao = new AreaDaoImpl();
 ListArea> areas = areaDao.findAreaByCid(Integer.parseInt(cid));

 response.getWriter().write(JSONObject.toJSONString(areas));
 }

 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 this.doPost(request, response);
 }
}

JSP頁面

%@ page contentType="text/html;charset=UTF-8" language="java" %>
html>
head>
 title>三級聯動/title>
 script type="text/javascript" src="js/jquery-1.8.3.js">/script>
/head>
body>
script type="text/javascript">
 $(function () {
 $.ajax({
 type:"get",
 url:"findAll",
 dataType:"json",
 success:function (data) {
 var obj=$("#province");
 for(var i=0;idata.length;i++){
 var ob="option value='"+data[i].pid+"'>"+data[i].pname+"/option>";
 obj.append(ob);
 }
 }
 })

 $("#province").change(function () {
 $("#city option").remove();
 $.ajax({
 type:"get",
 async:false,
 url:"findCityByPid?pid="+$("#province").val(),
 dataType:"json",
 success:function (data) {
 var obj=$("#city");
 for(var i=0;idata.length;i++){
 var ob="option value='"+data[i].cid+"'>"+data[i].cname+"/option>";
 obj.append(ob);
 }
 }
 })
 });

 $("#city,#province").change(function () {
 $("#area option").remove();
 $.ajax({
 type:"get",
 async:false,
 url:"findAreaByCid?cid="+$("#city").val(),
 dataType:"json",
 success:function (data) {
 var obj=$("#area");
 for(var i=0;idata.length;i++){
 var ob="option value='"+data[i].aid+"'>"+data[i].aname+"/option>";
 obj.append(ob);
 }
 }
 })
 });
 });
/script>
select name="province" id="province">
 option value="0">請選擇/option>
/select>省
select name="city" id="city">
 option value="0">請選擇/option>
/select>市
select name="area" id="area">
 option value="0">請選擇/option>
/select>縣
/body>
/html>

實現結果如下:

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • jQuery ajax實現省市縣三級聯動
  • ajax實現無刷新省市縣三級聯動
  • AJAX和WebService實現省市縣三級聯動具體代碼

標簽:邯鄲 樂山 衡陽 內江 婁底 德陽 海南 黔東

巨人網絡通訊聲明:本文標題《Ajax實現省市縣三級聯動》,本文關鍵詞  Ajax,實現省,市縣,三級,聯動,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Ajax實現省市縣三級聯動》相關的同類信息!
  • 本頁收集關于Ajax實現省市縣三級聯動的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 国产精品18久久久久久久久| 亚洲午夜电影网| 19禁大尺度无遮挡无码网站| 性生生活10分钟以上| 老王小说| 日本x色视频| japan年轻护士tube| 男女激情视频| 解开白丝老师的短裙猛烈进入| 老师太大了快停下| 亚洲ww| 阿银被爆?3D在线观看| 美女胸屁股无遮挡| jizz18中国| 国产精品亚洲AV片最刺激黄 | bbw尿交| 欧美综合区自拍亚洲综合天堂| 粗大呻吟销魂高潮小龙女| 久久国产精品国产精欧洲欧洲黄页| 嗯嗯啊啊啊啊不要| 看女友3p我硬了| 98午夜AV国产精品一区二区| 制服丝袜_1页_爱中色综合| 東京熱大亂交在线AV一区二区| 看**视频一级毛片| 色噜噜狠狠色综合免费视频| 亚洲Av日韩综合A∨蜜月Av| 免费街拍裙底无内裤视频网站 | bl文全肉高hnp| WC偷拍精品| 丰满熟女乱婬A片毛片| 被女闺蜜捆绑震蛋折磨调教| 亚洲国产午夜精品乱码| 中文幕无线码中文字蜜桃| 欧美??????JAPPT0| 非洲性videosxxxxhd| 女人怎么才能水越来越多| 重口 变态 扩张 改造 肉小说| 国产老头老太作爱视频| 成人精品A片免费观看直播69| 欧美色第一页|