成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁技術(shù)文章
文章詳情頁

AJAX實(shí)現(xiàn)數(shù)據(jù)的增刪改查操作詳解【java后臺】

瀏覽:624日期:2022-06-11 17:03:10

本文實(shí)例講述了AJAX實(shí)現(xiàn)數(shù)據(jù)的增刪改查操作。分享給大家供大家參考,具體如下:

主頁:index.html

<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script> </head> <body> 編號:<input type="text" value="" id="pno"/><br> 姓名:<input type="text" value="" id="name"/><br> 性別:男:<input type="radio" name="sex" value="男">女:<input type="radio" name="sex" value="女"><br> 年齡:<select id="age">  <option value="15">15</option>  <option value="16">16</option>  <option value="17">17</option>  <option value="18">18</option>  <option value="19">19</option>  <option value="20">20</option>  <option value="21">21</option>  <option value="22">22</option>  <option value="23">23</option>  <option value="24">24</option>  <option value="25">25</option> </select><br> 身高:<input type="text" value="" id="height"/><br> 體重:<input type="text" value="" id="weight"/><br> <input type="button" value="插入" id="btn_1" onclick="submit()"/> <br> <br> <br>  編號:<input type="text" value="" id="pno_query"/> <input type="button" value="查詢" id="btn_2" onclick="query()"/> <table id="queryResult">  <tr>  <td>編號</td>  <td>姓名</td>  <td>性別</td>  <td>年齡</td>  <td>身高</td>  <td>體重</td>  </tr>  <tr>  <td></td>  <td></td>  <td></td>  <td></td>  <td></td>  <td></td>  </tr> </table>   <br> <br> <br> 編號:<input type="text" value="" id="pno_del"/> <input type="button" value="刪除" id="btn_3" onclick="del()"/>  <br> <br> <br> 編號:<input type="text" value="" id="pno_up"/><br> 姓名:<input type="text" value="" id="name_up"/><br> 性別:男:<input type="radio" name="sex_up" value="男">女:<input type="radio" name="sex_up" value="女"><br> 年齡:<select id="age_up">  <option value="15">15</option>  <option value="16">16</option>  <option value="17">17</option>  <option value="18">18</option>  <option value="19">19</option>  <option value="20">20</option>  <option value="21">21</option>  <option value="22">22</option>  <option value="23">23</option>  <option value="24">24</option>  <option value="25">25</option> </select><br> 身高:<input type="text" value="" id="height_up"/><br> 體重:<input type="text" value="" id="weight_up"/><br> <input type="button" value="更新" id="btn_4" onclick="update()"/>  </body>  <script type="text/javascript"> /* var x = $("#queryResult").html();  for(var i=0; i < 20 ; i++) {  x += "<tr><td></td><td></td><td></td><td></td><td></td><td></td></tr>"; } $("#queryResult").html(x);*/ function submit() { var pno = $("#pno").val(); var name = $("#name").val(); var sex = $("input[name="sex"]:checked").val(); var age = $("#age").val(); var height = $("#height").val(); var weight = $("#weight").val();  var data={    "pno":pno,  "name":name,  "sex":sex,  "age":age,  "height":height,  "weight" : weight }   $.ajax({  type : "post",  url : "Hello",  data : data,  cache : true,  async : true,  success: function (data ,textStatus, jqXHR){     if(data.code == 200){      alert("插入成功了");     }else{      alert(data.message);     }   },     error:function (XMLHttpRequest, textStatus, errorThrown) {                alert(typeof(errorThrown));     }   }); }   function query() {  var pno = $("#pno_query").val();  var str = ["編號","姓名","性別","年齡","身高","體重"]; $.ajax({  type : "post",  url : "HelloQuery",  data : {  "pno": pno  },  cache : true,  async : true,  success: function (data ,textStatus, jqXHR){  //data = $.parseJSON(data);  var j = 0;  var x = 1;  //for(var i=1; i <20; i++) {   for(var p in data){//遍歷json對象的每個(gè)key/value對,p為key   console.log(data[p]);   if(j == 6) {    j = 0;    x++;   }    $("#queryResult tr:eq("+x+") td:eq("+j+")").html(data[p]);    console.log(data[p]);    j++;   }  //}              },     error:function (XMLHttpRequest, textStatus, errorThrown) {                alert(typeof(errorThrown));     }   }); }  function del() { var pno = $("#pno_del").val();   $.ajax({  type : "post",  url : "HelloDelete",  data : {  "pno": pno  },  cache : true,  async : true,  success: function (data ,textStatus, jqXHR){  if(data.code == 200){      alert("刪除成功了");     }else{      alert(data.message);     }   },     error:function (XMLHttpRequest, textStatus, errorThrown) {                alert(typeof(errorThrown));     }   }); }  function update() { var pno = $("#pno_up").val(); var name = $("#name_up").val(); var sex = $("input[name="sex_up"]:checked").val(); var age = $("#age_up").val(); var height = $("#height_up").val(); var weight = $("#weight_up").val();  var data={    "pno":pno,  "name":name,  "sex":sex,  "age":age,  "height":height,  "weight" : weight }   $.ajax({  type : "post",  url : "HelloUpdate",  data : data,  cache : true,  async : true,  success: function (data ,textStatus, jqXHR){     if(data.code == 200){      alert("更新成功了");     }else{      alert(data.message);     }   },     error:function (XMLHttpRequest, textStatus, errorThrown) {                alert(typeof(errorThrown));     }   }); }    </script></html>

增加的Serlvet:Hello.java

package com.web; import java.io.IOException;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 com.mysql.MysqlUtil; /** * Servlet implementation class Hello */@WebServlet("/Hello")public class Hello extends HttpServlet { private static final long serialVersionUID = 1L;      /**   * @see HttpServlet#HttpServlet()   */  public Hello() {    super();    // TODO Auto-generated constructor stub  }  /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); }  /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  response.setCharacterEncoding("utf-8"); response.setContentType("application/json; charset=utf-8");  String pno = request.getParameter("pno"); String name = request.getParameter("name"); String sex = request.getParameter("sex"); String age = request.getParameter("age"); String height = request.getParameter("height"); String weight = request.getParameter("weight");  String sqlInsert = "INSERT INTO Person (Pno,Pname,Psex,Page,Pheight,Pweight) VALUES(""; sqlInsert += pno +"",""; sqlInsert += name +"",""; sqlInsert += sex +"","; sqlInsert += age +","; sqlInsert += height +","; sqlInsert += weight +")";  int message = MysqlUtil.add(sqlInsert); String rep = ""; if(message == 1) {  rep = "{\"code\":200,\"message\":\"成功插入數(shù)據(jù)庫\"}"; }else {  rep = "{\"code\":\"999\",\"message\":\"插入失敗了\"}"; } response.getWriter().write(rep);   } }

刪除的Servlet:HelloDelete.java

package com.web; import java.io.IOException;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 com.mysql.MysqlUtil; /** * Servlet implementation class HelloDelete */@WebServlet("/HelloDelete")public class HelloDelete extends HttpServlet { private static final long serialVersionUID = 1L;      /**   * @see HttpServlet#HttpServlet()   */  public HelloDelete() {    super();    // TODO Auto-generated constructor stub  }  /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); }  /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setCharacterEncoding("utf-8"); response.setContentType("application/json; charset=utf-8");  String pno = request.getParameter("pno");   String sqlDel = "delete from Person where pno="+pno;   int message = MysqlUtil.del(sqlDel); String rep = ""; if(message == 1) {  rep = "{\"code\":\"200\",\"message\":\"成功刪除\"}"; }else {  rep = "{\"code\":\"999\",\"message\":\"刪除失敗\"}"; } response.getWriter().write(rep); } }

更新的Servlet:HelloUpdate.java

package com.web; import java.io.IOException;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 com.mysql.MysqlUtil; /** * Servlet implementation class HelloUpdate */@WebServlet("/HelloUpdate")public class HelloUpdate extends HttpServlet { private static final long serialVersionUID = 1L;      /**   * @see HttpServlet#HttpServlet()   */  public HelloUpdate() {    super();    // TODO Auto-generated constructor stub  }  /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); }  /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setCharacterEncoding("utf-8"); response.setContentType("application/json; charset=utf-8");  String pno = request.getParameter("pno"); String name = request.getParameter("name"); String sex = request.getParameter("sex"); String age = request.getParameter("age"); String height = request.getParameter("height"); String weight = request.getParameter("weight");  String sqlupdate = "update Person set ";// sqlupdate += "Pno=""+ pno +"","; sqlupdate += "Pname=""+ name +"","; sqlupdate += "Psex=""+ sex +"","; sqlupdate += "Page="+ age +","; sqlupdate += "Pheight="+ height +","; sqlupdate += "Pweight="+ weight; sqlupdate += " where Pno=""+pno+"""; System.out.println(sqlupdate); int message = MysqlUtil.update(sqlupdate); String rep = ""; if(message == 1) {  rep = "{\"code\":\"200\",\"message\":\"成功插入數(shù)據(jù)庫\"}"; }else {  rep = "{\"code\":\"999\",\"message\":\"插入失敗了\"}"; } response.getWriter().write(rep);  } }

查詢的Servlet:HelloQuery.java

package com.web; import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import java.util.List;import java.util.Map; 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 com.mysql.MysqlUtil; /** * Servlet implementation class HelloQuery */@WebServlet("/HelloQuery")public class HelloQuery extends HttpServlet { private static final long serialVersionUID = 1L;      /**   * @see HttpServlet#HttpServlet()   */  public HelloQuery() {    super();    // TODO Auto-generated constructor stub  }  /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); }  /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setCharacterEncoding("utf-8"); response.setContentType("application/json; charset=utf-8"); String pno = request.getParameter("pno"); String[] params = {"Pno","Pname","Psex","Page","Pheight","Pweight"}; String sql = "select * from Person where Pno="+pno; String data = "{";  String[] str = {"編號","姓名","性別","年齡","身高","體重"}; List<Map<String,String>> listmap = new ArrayList<>(); listmap = MysqlUtil.show(sql, params); for(int i =0 ; i<listmap.size();i++) {    for(int j=0 ; j<listmap.get(i).size();j++) {  data += "\""+str[j]+"\":"+"\""+listmap.get(i).get(params[j])+"\",";    } } data = data.substring(0, data.length()-1); data += "}";   System.out.println(data); response.getWriter().write(data); }   }

頁面如下:

對應(yīng)的數(shù)據(jù)庫:

git克隆地址:https://github.com/dreamiboy/JDBCUtil.git

更多關(guān)于ajax相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jquery中Ajax用法總結(jié)》、《JavaScript中ajax操作技巧總結(jié)》、《PHP+ajax技巧與應(yīng)用小結(jié)》及《asp.net ajax技巧總結(jié)專題》

希望本文所述對大家ajax程序設(shè)計(jì)有所幫助。

標(biāo)簽: Ajax
相關(guān)文章:
成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久
国产精品一二| 性久久久久久久| 日韩影院在线观看| 亚洲美女一区| 综合久久久久久| 国产综合欧美在线看| 欧美国产日本韩| 91美女片黄在线| 精品国精品国产| 国产精品一品视频| 欧美剧在线免费观看网站| 蜜桃av一区二区三区电影| 色综合久久久久综合99| 午夜精品福利一区二区三区av | 日韩午夜在线观看视频| 国产一区二区不卡老阿姨| 欧美亚洲综合在线| 蜜桃av噜噜一区| 欧美日韩在线播放一区| 激情五月播播久久久精品| 欧美日韩国产大片| 精品亚洲aⅴ乱码一区二区三区| 欧美综合一区二区三区| 久久精品国产亚洲a| 欧美性生交片4| 青青青伊人色综合久久| 欧美亚洲综合在线| 国产专区综合网| 日韩女优av电影| k8久久久一区二区三区 | 免费在线观看日韩欧美| 欧美日韩一级大片网址| 国产精品一区二区你懂的| 日韩欧美一级精品久久| caoporn国产精品| 国产欧美日韩精品一区| 亚洲国产欧美日韩| 亚洲国产精品影院| 在线观看av一区| 国产一区二区调教| 精品国产一区二区国模嫣然| 欧美粗暴jizz性欧美20| 亚洲色欲色欲www| 麻豆精品传媒视频| 精品一区二区三区久久| 欧美电影免费观看高清完整版在线 | 鲁大师成人一区二区三区| 石原莉奈在线亚洲三区| 欧美欧美午夜aⅴ在线观看| 成人黄色在线网站| 久久蜜桃一区二区| 9久re热视频在线精品| 免费成人小视频| 欧美α欧美αv大片| 国产精品www994| 午夜一区二区三区在线观看| 欧美怡红院视频| 成人免费视频免费观看| 中文字幕av一区 二区| 亚洲一区二区三区免费观看 | 亚洲午夜一区| 日本成人在线电影网| 日韩免费性生活视频播放| 黄色在线成人| 青椒成人免费视频| 欧美精品一区二区在线观看| 亚洲人体偷拍| 精品伊人久久久久7777人| 久久久久久久国产精品影院| 亚洲毛片av| 奇米888四色在线精品| 日韩精品最新网址| 亚洲第一区色| 久久精品噜噜噜成人av农村| 久久久久久日产精品| 国产精品久久久久久模特| 国产在线精品一区二区不卡了| 久久久国产一区二区三区四区小说| 国产精品久久久久久久久久直播| 精品一区二区三区免费视频| 国产精品麻豆一区二区| 欧美在线你懂的| 欧美成ee人免费视频| 日韩黄色免费电影| 国产亚洲成aⅴ人片在线观看| 亚洲综合国产| 懂色av中文字幕一区二区三区| 亚洲色图视频网| 欧美精品日日鲁夜夜添| 亚洲无线视频| 国产成人精品免费网站| 亚洲免费伊人电影| 欧美一卡2卡三卡4卡5免费| 在线一区日本视频| 盗摄精品av一区二区三区| 亚洲蜜臀av乱码久久精品| 91精品国产一区二区三区蜜臀| 激情久久久久| 麻豆精品在线播放| 亚洲欧洲另类国产综合| 欧美精品国产精品| 99在线精品视频在线观看| 成人av免费观看| 欧美aaaaa成人免费观看视频| 国产精品美女一区二区三区| 欧美群妇大交群中文字幕| 亚洲另类自拍| av网站免费线看精品| 日本欧美加勒比视频| 中文字幕人成不卡一区| 日韩视频免费观看高清完整版在线观看| 亚洲专区一区二区三区| 欧美日韩调教| 福利一区在线观看| 麻豆国产欧美一区二区三区| 亚洲欧美一区二区三区久本道91| 日韩美女视频一区二区在线观看| 久久午夜视频| 极品日韩久久| www.性欧美| 美女免费视频一区| 亚洲一区二区在线免费看| 国产日韩精品视频一区| 欧美肥妇bbw| 一本色道综合亚洲| 在线看片一区| 91丨porny丨中文| 国产精品18久久久久久久网站| 午夜一区二区三区视频| 中文字幕一区二区三区av| 欧美电视剧在线观看完整版| 欧洲国产伦久久久久久久| 国产精品一区免费观看| 亚洲性图久久| 午夜欧美视频| av爱爱亚洲一区| 国产精品一区在线| 另类人妖一区二区av| 亚洲国产婷婷综合在线精品| 国产精品久久久久久久久久免费看| 精品久久久影院| 91精品国产综合久久婷婷香蕉 | 亚洲国产美国国产综合一区二区| 国产免费久久精品| 日韩欧美视频在线| 欧美日本韩国一区二区三区视频| 狼狼综合久久久久综合网| 亚洲一区欧美二区| 欧美高清视频一区| 丁香六月综合激情| 国产盗摄一区二区| 国产麻豆91精品| 久久99久久久久| 人人爽香蕉精品| 日韩成人一级大片| 日韩精品91亚洲二区在线观看| 亚洲国产精品一区二区www在线| 亚洲欧美怡红院| 国产精品成人一区二区三区夜夜夜| 国产三级三级三级精品8ⅰ区| 欧美精品一区在线观看| 欧美不卡一区二区| 精品国产一区二区亚洲人成毛片 | 欧美肥妇bbw| 欧美日韩一级片网站| 91福利区一区二区三区| 久久天天狠狠| 色欧美88888久久久久久影院| 噜噜噜在线观看免费视频日韩| 香蕉久久久久久久av网站| 国产精品视频免费观看| 亚洲一区不卡| 久久黄色网页| 久久青青草原一区二区| 久久久蜜桃一区二区人| 一本色道久久综合精品竹菊| 色欧美88888久久久久久影院| 91久久人澡人人添人人爽欧美| 欧洲av一区二区嗯嗯嗯啊| 欧美三级韩国三级日本三斤| 欧美日韩国产片| 欧美一区二区三区视频在线观看| 日韩午夜中文字幕| 久久伊人中文字幕| 国产精品丝袜91| 一区免费观看视频| 一区二区免费看| 丝袜亚洲另类丝袜在线| 日韩av电影天堂| 国产在线视频一区二区三区| 国产激情91久久精品导航| 国产成人av电影在线| 91亚洲精品乱码久久久久久蜜桃| 欧美日韩亚洲一区二区三区四区| 亚洲第一区色| 久久性天堂网| 欧美剧在线免费观看网站 | 午夜久久久久久久久| 麻豆国产欧美一区二区三区| 日韩电影在线一区|