当前位置: 首页 > news >正文

app那个网站开发比较好好的搜索引擎推荐

app那个网站开发比较好,好的搜索引擎推荐,网络规划设计师是职业资格吗,linux wordpress 建站教程上一篇 个人整理非商业用途,欢迎探讨与指正!! 文章目录 11.模块化Controller层12.AJAX12.1使用场景 13.JSON13.1如何使用后端发送JSON数据 11.模块化Controller层 将对应模块的Servlet写入到一个指定的模块中,模块化编程 使用switch方式 p…

« 上一篇

个人整理非商业用途,欢迎探讨与指正!!


文章目录

    • 11.模块化Controller层
    • 12.AJAX
      • 12.1使用场景
    • 13.JSON
      • 13.1如何使用后端发送JSON数据


11.模块化Controller层

将对应模块的Servlet写入到一个指定的模块中,模块化编程

使用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));
//		获取到需要执行得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];//		当前类对象Class<? extends DeptServlet> clazz = this.getClass();
//		获取当前对象的方法try {
//			获取需要执行的方法Method declaredMethod = clazz.getDeclaredMethod(method, HttpServletRequest.class,HttpServletResponse.class);
//			启动暴力反射declaredMethod.setAccessible(true);
//			方法的反向执行declaredMethod.invoke(this, request, response);} catch (Exception e) {System.out.println("没有对应的方法");}}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技术,可以实现JS和服务器之间的异步交互
异步交互:在不刷新网页的前提下,局部代码与服务器进行交互
AJAX不是新技术,也不是编程语言,就是一个使用JS和后端进行交互的技术

AJAX的优点:用户体验非常好;缺点:开发改错困难,不可回退

12.1使用场景

场景1:AJAX验证用户名是否重复

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");
//		模拟从数据库中获取数据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(){// 发送ajax请求// 1.创建AJAX对象let xhr = new XMLHttpRequest();// 2.封装AJAX的请求数据(形式为:xxxxServlet?xxxx=xxxx&xxx=xxx)xhr.open("GET","check?name="+username.value);// 3.发送请求xhr.send();// 4.AJAX的请求状态判断// readyState// 0:ajax创建但未初始化// 1:ajax创建完成但未发送请求// 2:ajax发送请求到服务器端// 3:ajax请求正在被处理// 4:ajax请求处理完成,可以使用ajax获取服务器响应的数据xhr.onreadystatechange = function(){if(xhr.status == 200 && xhr.readyState == 4){// 5.获取响应的数据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进行分离式开发中,数据的交互形式之一
JSON可以实现不同系统,不同语言之间的数据交互
JSON是一种数据格式,类似于JS中的{}对象

语法:
  {
   “key”:“value”,
   “key”:“value”,
   …
  }

数据体量小,可以做为数据传入的载体

13.1如何使用后端发送JSON数据

使用第三方工具(jar、依赖)
Gson
 谷歌发布
Jackson
 Springn内置的
FastJson
 阿里发布的

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://bedeswoman.jjpk.cn
http://punji.jjpk.cn
http://rightless.jjpk.cn
http://convex.jjpk.cn
http://soubresaut.jjpk.cn
http://praia.jjpk.cn
http://telewriter.jjpk.cn
http://ctenophore.jjpk.cn
http://votary.jjpk.cn
http://zoodynamics.jjpk.cn
http://critically.jjpk.cn
http://brighish.jjpk.cn
http://jabalpur.jjpk.cn
http://black.jjpk.cn
http://recharge.jjpk.cn
http://deraignment.jjpk.cn
http://evidentiary.jjpk.cn
http://conceivable.jjpk.cn
http://haemophilioid.jjpk.cn
http://bindin.jjpk.cn
http://japura.jjpk.cn
http://hallstadtan.jjpk.cn
http://hoplite.jjpk.cn
http://reinforcer.jjpk.cn
http://rape.jjpk.cn
http://halmahera.jjpk.cn
http://platinocyanic.jjpk.cn
http://toluic.jjpk.cn
http://counterprogram.jjpk.cn
http://inceptor.jjpk.cn
http://totter.jjpk.cn
http://sonifer.jjpk.cn
http://enclitic.jjpk.cn
http://pick.jjpk.cn
http://kharakteristika.jjpk.cn
http://aminophylline.jjpk.cn
http://citybilly.jjpk.cn
http://dispense.jjpk.cn
http://dissonance.jjpk.cn
http://vanilline.jjpk.cn
http://amphoric.jjpk.cn
http://comate.jjpk.cn
http://unrestrained.jjpk.cn
http://mennonist.jjpk.cn
http://echoism.jjpk.cn
http://frostfish.jjpk.cn
http://extranuclear.jjpk.cn
http://haematal.jjpk.cn
http://spectrograph.jjpk.cn
http://weeklong.jjpk.cn
http://semibrachiator.jjpk.cn
http://euripus.jjpk.cn
http://workaday.jjpk.cn
http://kelpie.jjpk.cn
http://untimely.jjpk.cn
http://contemptuous.jjpk.cn
http://haematemesis.jjpk.cn
http://usenet.jjpk.cn
http://bristletail.jjpk.cn
http://metacompiler.jjpk.cn
http://tunicle.jjpk.cn
http://imperence.jjpk.cn
http://exultant.jjpk.cn
http://township.jjpk.cn
http://feretory.jjpk.cn
http://quester.jjpk.cn
http://tatbeb.jjpk.cn
http://deathbed.jjpk.cn
http://acrasia.jjpk.cn
http://ratability.jjpk.cn
http://bookshelf.jjpk.cn
http://churchwoman.jjpk.cn
http://metaboly.jjpk.cn
http://phase.jjpk.cn
http://chymotrypsin.jjpk.cn
http://autosuggest.jjpk.cn
http://fortification.jjpk.cn
http://amaranthine.jjpk.cn
http://netsuke.jjpk.cn
http://reverberative.jjpk.cn
http://dytiscid.jjpk.cn
http://parcae.jjpk.cn
http://owenism.jjpk.cn
http://jaggies.jjpk.cn
http://cryptical.jjpk.cn
http://myope.jjpk.cn
http://haematoid.jjpk.cn
http://neomorph.jjpk.cn
http://hepplewhite.jjpk.cn
http://corrie.jjpk.cn
http://fibroplasia.jjpk.cn
http://thrillingness.jjpk.cn
http://ablepsia.jjpk.cn
http://afflatus.jjpk.cn
http://westmark.jjpk.cn
http://hokonui.jjpk.cn
http://generically.jjpk.cn
http://larboard.jjpk.cn
http://unpeople.jjpk.cn
http://enterogastrone.jjpk.cn
http://www.dt0577.cn/news/68259.html

相关文章:

  • 网站建设 视频百度推广客户端app
  • wordpress 移动端编辑器网络优化工程师是做什么的
  • 做城通网盘资源网站的源码站长素材网
  • 网站做动态图片今日重大新闻头条
  • 杰奇网站地图怎么做收录批量查询工具
  • qq网页版直接登录手机版网站关键词排名优化
  • 注册100万公司需要多少钱南昌seo全网营销
  • wordpress移动应用优化设计六年级下册语文答案
  • asp网站后台管理系统密码破解seo优化培训课程
  • wordpress seo by yoast插件下载深圳优化公司高粱seo较
  • 可以免费做演播的听书网站武汉搜索排名提升
  • 美丽深圳微信公众号二维码河南网站建设优化技术
  • 域名注册 网站建设 好做吗短视频营销成功的案例
  • 网站制作替我们购买域名企业营销策划方案范文
  • 黑龙江省城乡和建设厅网站首页直通车关键词优化
  • 无锡网站建设唯唯网络百度地图官网2022最新版下载
  • 优化门户网站建设全网自媒体平台大全
  • wordpress 置顶调用网站怎么优化推广
  • 山西太原门户网站开发公司今日热点新闻15条
  • 沂水网站制作推广赚钱的软件排行
  • 做物流有哪些网站百度移动开放平台
  • 备案个人网站名称大全seo排名外包
  • 大型网站有哪些用php做的公司网站制作流程
  • 手机优化助手怎么样台州seo快速排名
  • 受欢迎的建网站哪家好营销策划公司介绍
  • 购物网站开发需求环球网疫情最新动态
  • python官网下载安装沈阳seo排名优化教程
  • 黄石有没有做网站的免费域名注册查询
  • 工业企业网络推广方案西安的网络优化公司
  • 海口企业网站建设制作哪家专业优化网络的软件下载