JavaWeb [Summary] - (Request and Response) The way the browser sends the request & the way the server responds

lead out

According to the synchronous, asynchronous, servlet forwarding and redirection, JavaScript and other related content learned earlier, it is necessary to think from the perspective of the way the browser sends the request and the way the server responds.
insert image description hereinsert image description here


Java Web related knowledge

1. Web page status code + web related background knowledge + how to build tomcat web project in idea

Servlet learning & Web-related background knowledge + web page status code (304) & preliminary JavaWeb project

insert image description here

2. Web request request: get and post, response response

web request request (post and get request) and response response + [case] the form is displayed on the web page

insert image description here

3. Synchronous request and asynchronous request Ajax, and asynchronous Json response

From Jsp synchronous request to Ajax axios asynchronous request, and asynchronous standard response
insert image description here

4. Under the axios of synchronous jsp and asynchronous ajax, think about forwarding or redirecting

When to use forwarding, when to use redirection & request request, response response

insert image description here

browser sends request

1. The address bar of the browser sends a request----all get

The method is all get

insert image description here

http://localhost:8080/day06/opus/updatePage/vue/update?id=47

2.form form: can be get or post

insert image description here

A case of the get method of a form form:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>图书添加页面</title>
</head>
<body>
<h1>添加图书信息</h1>

<form action="/day06/opus/addMess" method="get">
    书名:<input type="text" name="name"><br>
    简介:<input type="text" name="intro"><br>
    类型:
<%--    用forEach把类型信息拼出来--%>
    <select name="typeId">
        <c:forEach items="${bookTypes}" var="type">
            <option value="${type.id}">${
    
    type.name}</option>
        </c:forEach>
    </select><br>
    <span style="color: darkred">${
    
    msg}</span>
    <br>
    <input type="submit" value="提交">
    <input type="reset" value="重置">
</form>
</body>
</html>

The case of the get method

<form action="/day06/user/login" method="post">
<%--    没有name无法给后台传数据--%>
    用户名:<input type="text" name="username"><br>&nbsp;&nbsp;&nbsp;码:<input type="text" name="password"><br>
    <input type="submit" value="登陆">
    <span style="color: darkred">${
    
    msg}</span>
</form>

3. Hyperlink: equivalent to browser address bar—get

insert image description here

 <a href="/day06/opus/update?id=${opus.id}">修改</a>

server response

1. Responding to static pages: static resources under webapp;

insert image description here

2. Servlet processing: resp.getWriter().write("xxxxxxxxxx");

place resp.setContentType(“text/html;charset=utf-8”);
insert image description here

// 解决中文的显示问题
response.setCharacterEncoding("UTF-8"); // 设置成编码
response.setContentType("text/html;charset=utf-8"); // 展示的方式
response.getWriter().write("<h2>inputSuccess<h2>");

3.Servlet processing: redirect resp.sendRedirect("/path")

It can be redirected to servlet or jsp, allowing the browser to directly execute the address

insert image description here

resp.sendRedirect(req.getContextPath()+"/news/list.jsp");

4. Servlet processing: internal forwarding - servlet or jsp

Share data and pass it to the next servlet or jsp
insert image description here

req.getRequestDispatcher("/news/list").forward(req, resp);

5. Servlet processing: standard response format Json of asynchronous Ajax

import com.alibaba.fastjson.JSON;

resp.setContentType("application/json;charset=utf-8");
resp.getWriter().write(
		JSON.toJSONString(
				new ResData(3001, "不能删除别人", null)));

Applications

insert image description here

1. The case of synchronous request

Implementation of synchronous login and registration, and saving login information with session:

Synchronous login + registration - the realization of login and registration functions & iterative upgrade from html to jsp & session save login information

insert image description here

Under the synchronous request, the data list is displayed on the front end, displayed in pages, and the addition, deletion, modification and query of data

Use Jsp syntax to realize the paging display of data to only look at your own data + fuzzy query & iterative upgrade

Use Jsp syntax to realize the addition, deletion, modification and query of synchronous requests + delete permission control

insert image description here

2. The case of asynchronous request

Asynchronous implementation of login and registration functions, and a summary of bugs encountered in asynchronous requests
Asynchronous login + registration - iterative upgrade of login and registration functions & from Jsp to JavaScript + axios + vue & many bugs & synchronous to asynchronous

insert image description here
Asynchronous paging display, the realization of the whole process of adding, deleting, modifying and checking, and the difference analysis of synchronous and asynchronous in the process of adding, deleting, modifying and checking methods

Tomcat asynchronous paging + addition, deletion, modification and query - from synchronous to asynchronous & from jsp to js + axios + vue to realize data paging display & data addition, deletion, modification and query

insert image description here


Summarize

Background knowledge related to javaweb development;
summary of browser requests and server response methods;
synchronous and asynchronous login registration, page display, addition, deletion, modification and query cases;

Guess you like

Origin blog.csdn.net/Pireley/article/details/131234259