手动实现Tomcat底层机制+自己设计Servlet

文章目录

    • 1.Tomcat整体架构分析
      • 自己理解
    • 2.第一阶段
        • 1.实现功能
        • 2.代码
          • 1.TomcatV1.java
        • 3.调试阶段
          • 1.阻塞在readLine导致无法返回结果
        • 4.结果演示
    • 3.第二阶段
        • 1.实现功能
        • 2.代码
          • 1.RequestHander.java
          • 2.TomcatV2.java
        • 3.调试阶段
          • 1.发现每次按回车会接受到两次请求
        • 4.结果演示
    • 4.第三阶段
        • 1.实现功能
        • 2.总体框架
        • 3.代码实现
          • ===1.封装Request
          • 1.Request.java
          • 2.RequestHander.java
            • 单元测试报错Sock is closed
            • 原因
            • 修改之后
          • ===2.封装Response
          • 3.Response.java
          • 4.RequestHander.java
            • 单元测试无误
          • ===3.设计servlet规范
          • 5.Servlet.java
          • 6.HttpServlet.java
          • 7.CalServlet.java
          • 8.WebUtils.java
          • 9.RequestHander.java
            • 单元测试无误
          • ===4.xml + 反射初始化容器
          • 10.web.xml
          • 11.TomcatV3.java
          • 12.RequestHander.java
        • 4.总体调试阶段
          • 1.空指针异常
        • 5.结果演示
    • 5.课后作业
        • 1.更新WebUtils.java
          • 添加方法
        • 2.修改RequestHander.java
        • 3.cal.html
        • 4.调试阶段
        • 5.结果展示

1.Tomcat整体架构分析

image-20240126204326055

image-20240126204409213

自己理解

pdf下载

image-20240128100508870

2.第一阶段

1.实现功能

编写自己的Tomcat能接受浏览器的请求并返回结果

2.代码
1.TomcatV1.java
package Tomcat;import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;/*** @author 孙显圣* @version 1.0* 第一个版本的,可以接收浏览器的请求并返回信息*/
public class TomcatV1 {public static void main(String[] args) throws Exception {//在8080端口监听ServerSocket serverSocket = new ServerSocket(8081);System.out.println("Tomcat在8080端口监听");//只要不是手动关闭服务,则循环获取连接while (!serverSocket.isClosed()) {//获取连接Socket accept = serverSocket.accept();//获取输入流InputStream inputStream = accept.getInputStream();//使用转换流转为bufferedreader可以读取一行BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"));//字符串缓冲区String buff = null;while ((buff = bufferedReader.readLine()) != null) {//readline()在网络编程中,只有客户端的连接关闭了才会返回null,所以如果不设置别的判定条件退出,则会阻塞//由于请求信息最后有一个\r\n,读到这个\r\n会返回一个"",就可以退出了if (buff.equals("")) {break;}System.out.println(buff);}//tomcat向浏览器发送http响应,\r\n是换行String respHead ="HTTP/1.1 200 OK\r\n" +"Content-Type: text/html;charset=utf-8\r\n\r\n"; //响应头下面要空一行才能写响应体所以两个换行String resp = respHead + "<h1>hello world!</h1>";//获取输出流OutputStream outputStream = accept.getOutputStream();//输出outputStream.write(resp.getBytes());//关闭outputStream.flush();outputStream.close();inputStream.close();accept.close();}}
}
3.调试阶段
1.阻塞在readLine导致无法返回结果
  1. 最开始我并没有添加,如果readLine()读到""就退出循环的逻辑
  2. 后来发现readLine()在网络编程中,只有浏览器端关闭连接才会返回null
  3. 当读到了请求的\r\n的时候就会返回一个""字符串,然后阻塞在这里等待输入
  4. 所以在循环中添加当读到\r\n即返回""的时候退出即可
4.结果演示

image-20240127133045568

image-20240127133105064

3.第二阶段

1.实现功能

BIO线程模型支持多线程

image-20240127133413354

2.代码
1.RequestHander.java
package Tomcat.handler;import java.io.*;
import java.net.Socket;/*** @author 孙显圣* @version 1.0* 处理http请求的线程类*/
public class RequestHander implements Runnable{//定义一个socket属性private Socket socket = null;public RequestHander(Socket socket) {this.socket = socket;}public void run() {//可以对客户端或浏览器进行交互try {//获取输入流InputStream inputStream = socket.getInputStream();//转换成BufferedReader,方便按行读取BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"));System.out.println("tomcatV2接受到浏览器的数据如下:");//接受数据//设置缓冲String buff = null;//循环读取while ((buff = bufferedReader.readLine()) != null) {//判断是否读取到了\r\nif (buff.equals("")) {break; //读取完毕则退出循环,避免readLine阻塞}System.out.println(buff);}//获取输出流,返回信息到浏览器OutputStream outputStream = socket.getOutputStream();String respHead ="HTTP/1.1 200 OK\r\n" +"Content-Type: text/html;charset=utf-8\r\n\r\n"; //响应头下面要空一行才能写响应体所以两个换行String resp = respHead + "<h1>hello 孙显圣!</h1>";outputStream.write(resp.getBytes());//关闭outputStream.flush();outputStream.close();inputStream.close();socket.close();} catch (IOException e) {throw new RuntimeException(e);} finally {//确保关闭if (socket != null) {try {socket.close();} catch (IOException e) {throw new RuntimeException(e);}}}}
}
2.TomcatV2.java
package Tomcat;import Tomcat.handler.RequestHander;import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;/*** @author 孙显圣* @version 1.0*/
public class TomcatV2 {public static void main(String[] args) throws IOException {//在8080端口监听ServerSocket serverSocket = new ServerSocket(8080);System.out.println("TomcatV2在8080端口监听");//只要没有手动关闭则服务一直开启,循环监听while (!serverSocket.isClosed()) {Socket socket = serverSocket.accept();//将获取的socket交给线程类来处理RequestHander requestHander = new RequestHander(socket);Thread thread = new Thread(requestHander);thread.start(); //启动线程}}
}
3.调试阶段
1.发现每次按回车会接受到两次请求

image-20240127141739775

原因就是每次请求还要请求一下页面的小图标

image-20240127141931309

4.结果演示

image-20240127141956236

4.第三阶段

1.实现功能

image-20240127142230563

image-20240127142544134

2.总体框架

image-20240127215734459

3.代码实现
===1.封装Request
1.Request.java
package Tomcat.http;/*** @author 孙显圣* @version 1.0*/import java.io.*;
import java.util.HashMap;/*** 1.Request的作用就是封装http请求的数据 GET /tomcatv2?a=9&b=3 HTTP/1.1* 2.比如method(get), uri(/tomcat/cal),还有参数列表(num1&num2)* 3.相当于原生的HttpServletRequest*/
public class Request {private String method;private String uri;//存放参数列表private HashMap<String, String> parametersMapping = new HashMap<String, String>();//构造方法获取inputStream来封装信息public Request(InputStream inputStream) throws IOException {//转换成BufferedReaderBufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"));//读取第一行String s = bufferedReader.readLine();//将内容封装到属性String[] split = s.split(" ");method = split[0];//判断是否有参数列表int index = split[1].indexOf("?");if (index == -1) { //没有参数列表uri = split[1];}else { //有参数列表uri = split[1].substring(0,index);String parameters = split[1].substring(index + 1, split[1].length());String[] split1 = parameters.split("&"); //分割参数//判断?后面是否有东西if (split1 != null && !"".equals(split1)) {//遍历参数for (String parameterPair : split1) {String[] split2 = parameterPair.split("=");parametersMapping.put(split2[0],split2[1]);}}}//不能关闭,否则socket也就关闭了
//        inputStream.close();}public String getMethod() {return method;}public String getUri() {return uri;}public String getParameter(String name) {if (parametersMapping.containsKey(name)) {return parametersMapping.get(name);}else {return null;}}}
2.RequestHander.java
package Tomcat.handler;import Tomcat.http.Request;import java.io.*;
import java.net.Socket;/*** @author 孙显圣* @version 1.0* 处理http请求的线程类*/
public class RequestHander implements Runnable {//定义一个socket属性private Socket socket = null;public RequestHander(Socket socket) {this.socket = socket;}public void run() {//可以对客户端或浏览器进行交互try {//获取输入流InputStream inputStream = socket.getInputStream();//封装到Request里Request request = new Request(inputStream);//获取数据System.out.println(request.getUri() + " " + request.getMethod());System.out.println(request.getParameter("num1") + " " + request.getParameter("num2")+ " " + request.getParameter("num3"));//获取输出流,返回信息到浏览器OutputStream outputStream = socket.getOutputStream();String respHead ="HTTP/1.1 200 OK\r\n" +"Content-Type: text/html;charset=utf-8\r\n\r\n"; //响应头下面要空一行才能写响应体所以两个换行String resp = respHead + "<h1>hello 孙显圣!</h1>";outputStream.write(resp.getBytes());//关闭outputStream.flush();outputStream.close();inputStream.close();socket.close();} catch (IOException e) {throw new RuntimeException(e);} finally {//确保关闭if (socket != null) {try {socket.close();} catch (IOException e) {throw new RuntimeException(e);}}}}
}
单元测试报错Sock is closed

image-20240127153426609

原因

在Request.java中获取完参数顺便把inputStream关闭了,导致了Socket也一起关闭了,使得主线程在使用socket的时候出现了已经关闭的错误

image-20240127153538511

修改之后

image-20240127153742457

image-20240127153750759

===2.封装Response
3.Response.java
package Tomcat.http;/*** @author 孙显圣* @version 1.0*/import java.io.OutputStream;/*** 1.这个response对象可以封装OutputSream* 2.即可以通过这个对象返回http响应给浏览器* 3.相当于原生的HttpServletResponse*/
public class Response {private OutputStream outputStream = null;//封装一个响应头public static final String respHeader = "HTTP/1.1 200 OK\r\n" +"Content-Type: text/html;charset=utf-8\r\n\r\n"; //响应头下面要空一行才能写响应体所以两个换行public Response(OutputStream outputStream) {this.outputStream = outputStream;}//以后再Servlet里面获取输出流public OutputStream getOutputStream() {return outputStream;}
}
4.RequestHander.java
package Tomcat.handler;import Tomcat.http.Request;
import Tomcat.http.Response;import java.io.*;
import java.net.Socket;/*** @author 孙显圣* @version 1.0* 处理http请求的线程类*/
public class RequestHander implements Runnable {//定义一个socket属性private Socket socket = null;public RequestHander(Socket socket) {this.socket = socket;}public void run() {//可以对客户端或浏览器进行交互try {//获取输入流InputStream inputStream = socket.getInputStream();//封装到Request里Request request = new Request(inputStream);//获取数据System.out.println(request.getUri() + " " + request.getMethod());System.out.println(request.getParameter("num1") + " " + request.getParameter("num2")+ " " + request.getParameter("num3"));//获取输出流,返回信息到浏览器OutputStream outputStream = socket.getOutputStream();//封装到Response对象中Response response = new Response(outputStream);//获取输出流输出信息OutputStream outputStream1 = response.getOutputStream();outputStream1.write((response.respHeader + "<h1>response响应:你好,孙显圣</h1>").getBytes());//关闭outputStream.flush();outputStream.close();inputStream.close();socket.close();} catch (IOException e) {throw new RuntimeException(e);} finally {//确保关闭if (socket != null) {try {socket.close();} catch (IOException e) {throw new RuntimeException(e);}}}}
}
单元测试无误

image-20240127161328146

image-20240127161334862

===3.设计servlet规范
5.Servlet.java
package Tomcat.servlet;import Tomcat.http.Request;
import Tomcat.http.Response;import java.io.IOException;/*** @author 孙显圣* @version 1.0* 保留三个核心方法*/
public interface Servlet {void init() throws Exception;void service(Request request, Response response) throws IOException;void destroy();
}
6.HttpServlet.java
package Tomcat.servlet;import Tomcat.http.Request;
import Tomcat.http.Response;import java.io.IOException;/*** @author 孙显圣* @version 1.0*/
public abstract class HttpServlet implements Servlet {public void service(Request request, Response response) throws IOException {//抽象模板设计模式,判断类型来决定调用什么方法if ("GET".equalsIgnoreCase(request.getMethod())) {//以后会反射创建子类实例,调用子类的service方法,子类没有,就从父类找,然后再使用动态绑定到子类的doGet方法this.doGet(request, response);} else if ("POST".equalsIgnoreCase(request.getMethod())) {this.doPost(request, response);}}public abstract void doGet(Request request, Response response);public abstract void doPost(Request request, Response response);}
7.CalServlet.java
package Tomcat.servlet;import Tomcat.http.Request;
import Tomcat.http.Response;
import Tomcat.utils.WebUtils;import java.io.IOException;
import java.io.OutputStream;/*** @author 孙显圣* @version 1.0*/
public class CalServlet extends HttpServlet {public void doGet(Request request, Response response) {//完成计算任务int num1 = WebUtils.parseInt(request.getParameter("num1"), 0);int num2 = WebUtils.parseInt(request.getParameter("num2"), 0);int sum = num1 + num2;//返回计算结果给浏览器OutputStream outputStream = response.getOutputStream();String resp = Response.respHeader + "<h1>" + num1 + " + " + num2 + " = " + sum + "</h1>";try {outputStream.write(resp.getBytes());//关闭outputStream.flush();outputStream.close();} catch (IOException e) {throw new RuntimeException(e);}}public void doPost(Request request, Response response) {this.doGet(request, response);}public void init() throws Exception {}public void destroy() {}
}
8.WebUtils.java
package Tomcat.utils;/*** @author 孙显圣* @version 1.0*/
public class WebUtils {//把String类型转换成int类型,如果是非整数则返回默认值public static int parseInt(String str, int defaultVal) {try {return Integer.parseInt(str);} catch (NumberFormatException e) {System.out.println("转换失败");}return defaultVal;}}
9.RequestHander.java
package Tomcat.handler;import Tomcat.http.Request;
import Tomcat.http.Response;
import Tomcat.servlet.CalServlet;import java.io.*;
import java.net.Socket;/*** @author 孙显圣* @version 1.0* 处理http请求的线程类*/
public class RequestHander implements Runnable {//定义一个socket属性private Socket socket = null;public RequestHander(Socket socket) {this.socket = socket;}public void run() {//可以对客户端或浏览器进行交互try {//获取输入流InputStream inputStream = socket.getInputStream();//封装到Request里Request request = new Request(inputStream);//获取输出流,返回信息到浏览器OutputStream outputStream = socket.getOutputStream();//封装到Response对象中Response response = new Response(outputStream);CalServlet calServlet = new CalServlet();calServlet.service(request,response); //这个会调用他抽象父类的service方法inputStream.close();socket.close();} catch (IOException e) {throw new RuntimeException(e);} finally {//确保关闭if (socket != null) {try {socket.close();} catch (IOException e) {throw new RuntimeException(e);}}}}
}
单元测试无误

image-20240127170622206

===4.xml + 反射初始化容器

image-20240127172419183

10.web.xml

image-20240127200603422

image-20240127200517652

11.TomcatV3.java
package Tomcat;import Tomcat.handler.RequestHander;
import Tomcat.servlet.HttpServlet;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;/*** @author 孙显圣* @version 1.0*/
public class TomcatV3 {//设置两个hashmap容器,在启动的Tomcat的时候就初始化//存放名字和实例public static final ConcurrentHashMap<String, HttpServlet>servletMapping = new ConcurrentHashMap<String, HttpServlet>();//存放路径和名字public static final ConcurrentHashMap<String, String>servletUrlMapping = new ConcurrentHashMap<String, String>();public static void main(String[] args) throws MalformedURLException, DocumentException, ClassNotFoundException, InstantiationException, IllegalAccessException {TomcatV3 tomcatV3 = new TomcatV3();tomcatV3.init();tomcatV3.run();}//启动TomcatV3容器public void run() {try {ServerSocket serverSocket = new ServerSocket(8080);System.out.println("TomcatV3在8080端口监听");while (!serverSocket.isClosed()) { //只要没有手动关闭服务,就循环获取连接Socket socket = serverSocket.accept();//将socket交给线程处理RequestHander requestHander = new RequestHander(socket);new Thread(requestHander).start(); //启动线程}} catch (IOException e) {throw new RuntimeException(e);}}private void init() throws MalformedURLException, DocumentException, ClassNotFoundException, InstantiationException, IllegalAccessException {//获取该类的路径String path = TomcatV3.class.getResource("/").getPath();//使用dom4j读取web.xml文件//获取解析器SAXReader saxReader = new SAXReader();//读取文件Document read = saxReader.read(new File(path + "web.xml"));//获取根元素Element rootElement = read.getRootElement();//获取所有二级元素List<Element> servlet = rootElement.elements();//遍历所有二级元素,根据不同类型做处理for (Element element : servlet) {if ("servlet".equalsIgnoreCase(element.getName())) {//获取名字和全类名Element servletName = element.element("servlet-name");Element servletClass = element.element("servlet-class");//通过反射创建实例Class<?> aClass = Class.forName(servletClass.getText().trim()); //trim是清除空格HttpServlet httpServlet = (HttpServlet) aClass.newInstance();//将其放到容器中去servletMapping.put(servletName.getText(), httpServlet);} else if ("servlet-mapping".equalsIgnoreCase(element.getName())) {//获取名字和urlElement servletName = element.element("servlet-name");Element servletUrl = element.element("url-pattern");//将其放到容器中去servletUrlMapping.put("/tomcat" + servletUrl.getText(), servletName.getText());}}}}
12.RequestHander.java
package Tomcat.handler;import Tomcat.TomcatV3;
import Tomcat.http.Request;
import Tomcat.http.Response;
import Tomcat.servlet.CalServlet;
import Tomcat.servlet.HttpServlet;import java.io.*;
import java.net.Socket;/*** @author 孙显圣* @version 1.0* 处理http请求的线程类*/
public class RequestHander implements Runnable {//定义一个socket属性private Socket socket = null;public RequestHander(Socket socket) {this.socket = socket;}public void run() {//可以对客户端或浏览器进行交互try {//获取输入流InputStream inputStream = socket.getInputStream();//封装到Request里Request request = new Request(inputStream);//获取输出流,返回信息到浏览器OutputStream outputStream = socket.getOutputStream();//封装到Response对象中Response response = new Response(outputStream);String uri = request.getUri();String servletName = TomcatV3.servletUrlMapping.get(uri);if (servletName == null) {servletName = "";}HttpServlet httpServlet = TomcatV3.servletMapping.get(servletName);//判断是否得到了这个对象if (httpServlet != null) {httpServlet.service(request, response);} else {//没有得到则返回404String resp = Response.respHeader + "<h1>404 not found</h1>";response.getOutputStream().write(resp.getBytes());}inputStream.close();socket.close();} catch (IOException e) {throw new RuntimeException(e);} finally {//确保关闭if (socket != null) {try {socket.close();} catch (IOException e) {throw new RuntimeException(e);}}}}
}
4.总体调试阶段
1.空指针异常

image-20240127195609800

image-20240127200135939

5.结果演示

image-20240127200406441

image-20240127200413877

image-20240127200437664

5.课后作业

image-20240127201804124

image-20240127201735945

1.更新WebUtils.java
添加方法
    //判断是不是html格式的文件,如果是就直接读取文件内容并且返回truepublic static boolean isHtml(String uri, Response response) {//使用正则表达式匹配html文件String regStr = "(/.*)*/(.*\\.html)";Pattern compile = Pattern.compile(regStr);Matcher matcher = compile.matcher(uri);if (!matcher.find()) { //没匹配到就直接返回falsereturn false;}//得到html文件的路径String path = "D:\\Intelij IDEA Project\\java_web\\tomcat\\target\\classes\\" + matcher.group(2);System.out.println(path);//根据路径读取文件并存放到StringBuilder中StringBuilder stringBuilder = new StringBuilder();try {BufferedReader bufferedReader = new BufferedReader(new FileReader(path));String buf = null;while ((buf = bufferedReader.readLine()) != null) {stringBuilder.append(buf); //存放到stringBuilder中}//将stringBuilder的内容响应给浏览器String resp = Response.respHeader + stringBuilder.toString();response.getOutputStream().write(resp.getBytes());}catch (Exception e) {System.out.println("文件找不到!");return false; //返回false之后就会继续进行原来的逻辑,弹出404}//如果不出异常则说明响应成功return true;}
2.修改RequestHander.java

image-20240127215107134

3.cal.html
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<form action="/tomcat/CalServlet" method="get">num1:<input type="text" name="num1">num2:<input type="text" name="num2"><input type="submit" value="提交">
</form>
</body>
</html>
4.调试阶段
  1. 一直显示我的cal.html文件找不到,调了半个小时
  2. 原因是String path = TomcatV3.class.getResource("/").getPath();使用这个来获取的路径没有空格,而我的资源路径是这个D:\\Intelij IDEA Project\\java_web\\tomcat\\target\\classes\\,中间带了空格,真的是醉了,深刻体会到文件夹起名不要带空格的重要性了
5.结果展示

image-20240127215627956

image-20240127215633496

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/596262.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【服务器部署篇】Linux下安装Docker容器

作者介绍&#xff1a;本人笔名姑苏老陈&#xff0c;从事JAVA开发工作十多年了&#xff0c;带过大学刚毕业的实习生&#xff0c;也带过技术团队。最近有个朋友的表弟&#xff0c;马上要大学毕业了&#xff0c;想从事JAVA开发工作&#xff0c;但不知道从何处入手。于是&#xff0…

【自用笔记】【大数据】

1 mapreduce &#xff08;1&#xff09;Map任务的数量&#xff1a;由输入数据的大小决定的&#xff0c;如文件数量和大小、HDFS块大小以及FileInputFormat的设置等。每个MapSlot可以运行一个Map任务 &#xff08;2&#xff09;Reduce任务的数量&#xff08;分区数&#xff09;&…

配置Mysql集群主从复制报错

配置Mysql集群主从复制报错: 我在master创建了一个数据库&#xff08;demo_ds_0&#xff09;,然后又快速删除了。然后又再次创建了 demo_ds_0, 发现 slave 数据库没有将 demo_ds_0 库同步过来。 后面在 slave 数据库中执行 show slave status 发现 SLave_IO_Running 字段是 …

练习 17 Web [极客大挑战 2019]PHP

常见的网站源码备份文件名和后缀&#xff0c;反序列化攻击 unserialize()&#xff1a;wakeup绕过&#xff0c;private类以及属性序列化后的%00修改 开靶机 提到”备份“ 那看看有没有backup.php啥的 如果网站存在备份文件&#xff0c;常见的备份文件后缀名有&#xff1a;“.gi…

开源代码分享(17)-基于足球队训练算法(Football Team Training Algorithm,FTTA)的组合风速预测

参考文献&#xff1a; [1]Tian Z, Gai M. Football team training algorithm: A novel sport-inspired meta-heuristic optimization algorithm for global optimization[J]. Expert Systems with Applications, 2024, 245: 123088. 1.算法基本原理 足球队训练算法&#xff0…

练习14 Web [极客大挑战 2019]Upload

phtml格式绕过&#xff0c;burp修改content-type绕过&#xff0c;常见的文件上传存放目录名 题目就叫upload&#xff0c;打开靶机 直接上传一个图片格式的一句话木马&#xff0c;返回如下&#xff1a; 提交练习5和9中的两种可以执行图片格式php代码的文件&#xff0c;修改con…

前端三剑客 —— CSS (第四节)

目录 内容回顾&#xff1a; 1.常见样式 2.特殊样式 特殊样式 过滤效果 动画效果 动画案例&#xff1a; 渐变效果 其他效果&#xff1a; 多列效果 字体图标&#xff08;icon&#xff09; 内容回顾&#xff1a; 1.常见样式 text-shadow x轴 y轴 阴影的模糊程度 阴影的…

蓝桥杯-冶炼金属(二分求最大最小)

P9240 [蓝桥杯 2023 省 B] 冶炼金属 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 二分做法&#xff1a; #include<bits/stdc.h> using namespace std; #define int long long const int N 1e410; int n,a,b; int v[N],cnt[N]; int check(int x){for(int i1;i<n;i…

JS详解-设计模式

工厂模式&#xff1a; 单例模式&#xff1a; // 1、定义一个类class SingleTon{// 2、添加私有静态属性static #instance// 3、添加静态方法static getInstance(){// 4、判断实例是否存在if(!this.#instance){// 5、实例不存在&#xff0c;创建实例this.#instance new Single…

[AIGC] SpringMVC, Filter, Interceptor之间关系详解

在Web应用开发过程中&#xff0c;我们经常需要处理各样的HTTP请求和响应。在Spring框架中&#xff0c;我们主要借助SpringMVC、Filter和Interceptor来处理这些任务。那么&#xff0c;这三者之间有什么关系&#xff0c;又分别扮演着什么角色呢&#xff1f;本文将带你一探究竟。 …

VS Code 配置 cmake

CMake 用法参考 CMake学习 cmake使用详细教程&#xff08;日常使用这一篇就足够了&#xff09;_cmake教程-CSDN博客 手动添加 CMake 编译器的搜索路径 如果没有设置上面的路径&#xff0c;有些编译器是找不到的 指定cmake 生成文件的路径 生成makefile 等文件的路径 可以指…

Linux网卡IP地址配置错误的影响

在Linux系统中&#xff0c;网络配置是保持系统顺畅运行的关键一环。正确配置网卡的IP地址对于确保网络通信的准确性和效率至关重要。然而&#xff0c;如果在这个过程中发生错误&#xff0c;可能会带来一系列问题。让我们一起探讨一下&#xff0c;如果Linux网卡的IP地址配置错误…