国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁 > news >正文

app那個(gè)網(wǎng)站開發(fā)比較好內(nèi)部搜索引擎優(yōu)化

app那個(gè)網(wǎng)站開發(fā)比較好,內(nèi)部搜索引擎優(yōu)化,wordpress font awesome,wordpress站6個(gè)月300mb上一篇 個(gè)人整理非商業(yè)用途,歡迎探討與指正!! 文章目錄 11.模塊化Controller層12.AJAX12.1使用場景 13.JSON13.1如何使用后端發(fā)送JSON數(shù)據(jù) 11.模塊化Controller層 將對應(yīng)模塊的Servlet寫入到一個(gè)指定的模塊中,模塊化編程 使用switch方式 p…

? 上一篇

個(gè)人整理非商業(yè)用途,歡迎探討與指正!!


文章目錄

    • 11.模塊化Controller層
    • 12.AJAX
      • 12.1使用場景
    • 13.JSON
      • 13.1如何使用后端發(fā)送JSON數(shù)據(jù)


11.模塊化Controller層

將對應(yīng)模塊的Servlet寫入到一個(gè)指定的模塊中,模塊化編程

使用switch方式

package com.qf.servlet;import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;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 sun.rmi.transport.proxy.HttpReceiveSocket;/*** Servlet implementation class EmpServlet*/
@WebServlet("/emp/*")
public class EmpServlet extends HttpServlet {private static final long serialVersionUID = 1L;/*** @see HttpServlet#HttpServlet()*/public EmpServlet() {super();// TODO Auto-generated constructor stub}protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		請求的urlString requestURL = request.getRequestURL().toString();System.out.println(requestURL);String[] split = requestURL.split("/");
//		System.out.println(Arrays.toString(split));
//		獲取到需要執(zhí)行得Servlet方法String method = split[split.length-1];switch (method) {case "insert":insert(request,response);break;case "delete":delete(request,response);break;default:return;}}public void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {System.out.println("我是刪除方法");}public void insert(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {System.out.println("我是添加方法");}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubdoGet(request, response);}
}

使用反射

@WebServlet("/dept/*")
public class DeptServlet extends HttpServlet {private static final long serialVersionUID = 1L;public DeptServlet() {super();}protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {String requestURL = request.getRequestURL().toString();String[] split = requestURL.split("/");String method = split[split.length-1];//		當(dāng)前類對象Class<? extends DeptServlet> clazz = this.getClass();
//		獲取當(dāng)前對象的方法try {
//			獲取需要執(zhí)行的方法Method declaredMethod = clazz.getDeclaredMethod(method, HttpServletRequest.class,HttpServletResponse.class);
//			啟動(dòng)暴力反射declaredMethod.setAccessible(true);
//			方法的反向執(zhí)行declaredMethod.invoke(this, request, response);} catch (Exception e) {System.out.println("沒有對應(yīng)的方法");}}public void insert(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException  {System.out.println("添加方法");}private void delete(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException  {System.out.println("刪除方法");}private void update(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException  {System.out.println("修改方法");}protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubdoGet(request, response);}
}

12.AJAX

異步的JS與XML技術(shù),可以實(shí)現(xiàn)JS和服務(wù)器之間的異步交互
異步交互:在不刷新網(wǎng)頁的前提下,局部代碼與服務(wù)器進(jìn)行交互
AJAX不是新技術(shù),也不是編程語言,就是一個(gè)使用JS和后端進(jìn)行交互的技術(shù)

AJAX的優(yōu)點(diǎn):用戶體驗(yàn)非常好;缺點(diǎn):開發(fā)改錯(cuò)困難,不可回退

12.1使用場景

場景1:AJAX驗(yàn)證用戶名是否重復(fù)

package com.qf.servlet;import java.io.IOException;
import java.util.ArrayList;import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;/*** Servlet implementation class CheckNameServlet*/
@WebServlet("/check")
public class CheckNameServlet extends HttpServlet {private static final long serialVersionUID = 1L;public CheckNameServlet() {super();}protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {String name = request.getParameter("name");
//		模擬從數(shù)據(jù)庫中獲取數(shù)據(jù)ArrayList<String> list = new ArrayList<>();list.add("張三");list.add("李四");list.add("王五");list.add("tom");list.add("jack");list.add("rose");//		何如判斷name在list中boolean contains = list.contains(name);
//		false是可用 true是不可用
//		System.out.println(contains);
//		0不可用 1可用response.getWriter().print(contains?0:1);}protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubdoGet(request, response);}
}
<!DOCTYPE html>
<html><head><meta charset="utf-8"><title></title></head><body><input type="text" id="username"><span id="msg"></span><script>window.onload = function(){let username = document.querySelector("#username");let msg = document.querySelector("#msg");username.onblur = function(){// 發(fā)送ajax請求// 1.創(chuàng)建AJAX對象let xhr = new XMLHttpRequest();// 2.封裝AJAX的請求數(shù)據(jù)(形式為:xxxxServlet?xxxx=xxxx&xxx=xxx)xhr.open("GET","check?name="+username.value);// 3.發(fā)送請求xhr.send();// 4.AJAX的請求狀態(tài)判斷// readyState// 0:ajax創(chuàng)建但未初始化// 1:ajax創(chuàng)建完成但未發(fā)送請求// 2:ajax發(fā)送請求到服務(wù)器端// 3:ajax請求正在被處理// 4:ajax請求處理完成,可以使用ajax獲取服務(wù)器響應(yīng)的數(shù)據(jù)xhr.onreadystatechange = function(){if(xhr.status == 200 && xhr.readyState == 4){// 5.獲取響應(yīng)的數(shù)據(jù)let result = xhr.responseText;if(result == 0){msg.innerHTML = '用戶名已存在';msg.style.color = 'red';}else{msg.innerHTML = '√';msg.style.color = 'green';}}}}}</script></body>
</html>

13.JSON

配合AJAX進(jìn)行分離式開發(fā)中,數(shù)據(jù)的交互形式之一
JSON可以實(shí)現(xiàn)不同系統(tǒng),不同語言之間的數(shù)據(jù)交互
JSON是一種數(shù)據(jù)格式,類似于JS中的{}對象

語法:
??{
???“key”:“value”,
???“key”:“value”,
???…
??}

數(shù)據(jù)體量小,可以做為數(shù)據(jù)傳入的載體

13.1如何使用后端發(fā)送JSON數(shù)據(jù)

使用第三方工具(jar、依賴)
Gson
?谷歌發(fā)布
Jackson
?Springn內(nèi)置的
FastJson
?阿里發(fā)布的

package com.qf.test;import java.util.ArrayList;
import java.util.HashMap;import org.junit.Test;import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;public class TestJSON {@Testpublic void test01() {System.out.println("helloworld");}@Testpublic void test02() {Gson gson = new Gson();String json = gson.toJson("helloworld");System.out.println(json);}@Testpublic void test03() {Gson gson = new Gson();String json = gson.toJson(new Dog(1,"李四"));System.out.println(json);}@Testpublic void test04() {ArrayList<Dog> dogs = new ArrayList<>();dogs.add(new Dog(1,"1"));dogs.add(new Dog(2,"2"));dogs.add(new Dog(3,"3"));dogs.add(new Dog(4,"4"));String json = new Gson().toJson(dogs);System.out.println(json);}@Testpublic void test05() {ArrayList<Dog> dogs = new ArrayList<>();dogs.add(new Dog(1,"1"));dogs.add(new Dog(2,"2"));dogs.add(new Dog(3,"3"));dogs.add(new Dog(4,"4"));int currPage = 10;HashMap<String,Object> map = new HashMap<>();map.put("dogs", dogs);map.put("page", currPage);String json = new Gson().toJson(map);System.out.println(json);}@Testpublic void test06() throws Exception {Dog dog = new Dog(1,"1");ObjectMapper objectMapper = new ObjectMapper();String json = objectMapper.writeValueAsString(dog);System.out.println(json);}
}
http://aloenet.com.cn/news/28458.html

相關(guān)文章:

  • 網(wǎng)站可以叫做系統(tǒng)嗎企業(yè)培訓(xùn)課程
  • 蘇州公司網(wǎng)站seo外鏈推廣員
  • 空間鏈接制作網(wǎng)站百度推廣中心
  • 軟件測試培訓(xùn)一般多少錢長春seo排名優(yōu)化
  • 方特網(wǎng)站是誰做的seo案例視頻教程
  • 外國做掛的網(wǎng)站是多少錢外貿(mào)營銷型網(wǎng)站建設(shè)公司
  • my77738免費(fèi)域名查詢seo薪酬水平
  • seo 刷網(wǎng)站url南平網(wǎng)站seo
  • 免費(fèi)地方門戶網(wǎng)站系統(tǒng)寧波網(wǎng)絡(luò)推廣平臺
  • 2018年做視頻網(wǎng)站網(wǎng)站seo站長工具
  • 團(tuán)購網(wǎng)站 seo微信群推廣網(wǎng)站
  • 太湖云建站網(wǎng)站建設(shè)職業(yè)培訓(xùn)機(jī)構(gòu)需要什么資質(zhì)
  • 外貿(mào)網(wǎng)站圖片素材百度網(wǎng)盟推廣怎么做
  • 網(wǎng)頁設(shè)計(jì)品牌故事昆明百度關(guān)鍵詞優(yōu)化
  • 怎么做簡單地網(wǎng)站網(wǎng)站網(wǎng)絡(luò)排名優(yōu)化方法
  • 網(wǎng)站建設(shè)合同糾紛管轄seo優(yōu)化師就業(yè)前景
  • 營銷型企業(yè)網(wǎng)站建設(shè)教案北京競價(jià)托管代運(yùn)營
  • 做網(wǎng)站的實(shí)踐報(bào)告怎樣制作一個(gè)網(wǎng)站
  • wordpress 圖片自動(dòng)加水印東莞網(wǎng)站制作十年樂云seo
  • 石家莊做外貿(mào)網(wǎng)站軟文免費(fèi)發(fā)布平臺
  • 國際貨代做網(wǎng)站百度通用網(wǎng)址
  • 百度站長工具平臺登錄成都網(wǎng)站建設(shè)方案優(yōu)化
  • 網(wǎng)站建站系統(tǒng)站長工具搜索
  • 網(wǎng)站服務(wù)公司特點(diǎn)上海疫情又要爆發(fā)了
  • 網(wǎng)站開發(fā)總監(jiān)自助建站
  • 如何做服裝微商城網(wǎng)站建設(shè)關(guān)鍵字廣告
  • WordPress電影公司網(wǎng)站主題大連網(wǎng)站建設(shè)費(fèi)用
  • 包頭市建設(shè)工程安全監(jiān)督站網(wǎng)站萬能搜索引擎入口
  • 東莞網(wǎng)站優(yōu)化微信公眾號運(yùn)營推廣方案
  • 滾屏網(wǎng)站模板網(wǎng)站生成器