This article directory
- lead out
- Java Web related knowledge
-
- 1. Web page status code + web related background knowledge + how to build tomcat web project in idea
- 2. Web request request: get and post, response response
- 3. Synchronous request and asynchronous request Ajax, and asynchronous Json response
- 4. Under the axios of synchronous jsp and asynchronous ajax, think about forwarding or redirecting
- browser sends request
- server response
-
- 1. Responding to static pages: static resources under webapp;
- 2. Servlet processing: resp.getWriter().write("xxxxxxxxxx");
- 3.Servlet processing: redirect resp.sendRedirect("/path")
- 4. Servlet processing: internal forwarding --- servlet or jsp
- 5. Servlet processing: standard response format Json of asynchronous Ajax
- Applications
- Summarize
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.
Java Web related knowledge
1. Web page status code + web related background knowledge + how to build tomcat web project in idea
2. Web request request: get and post, response response
3. Synchronous request and asynchronous request Ajax, and asynchronous Json response
From Jsp synchronous request to Ajax axios asynchronous request, and asynchronous standard response
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
browser sends request
1. The address bar of the browser sends a request----all get
The method is all get
http://localhost:8080/day06/opus/updatePage/vue/update?id=47
2.form form: can be get or post
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>
密 码:<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
<a href="/day06/opus/update?id=${opus.id}">修改</a>
server response
1. Responding to static pages: static resources under webapp;
2. Servlet processing: resp.getWriter().write("xxxxxxxxxx");
place resp.setContentType(“text/html;charset=utf-8”);
// 解决中文的显示问题
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
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
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
1. The case of synchronous request
Implementation of synchronous login and registration, and saving login information with session:
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
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
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
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;