【高级网络程序设计】Week3-2 Servlet

一、 What are servlets?

1. 定义

(1)Servlets are Java’s answer to CGI:

programs that run on a web server acting as middle layer between HTTP request and databases or other applications.
Used for client requests that cannot be satisfied using pre-built (static) documents.
Used to generate dynamic web pages in response to client.

(2)图解

Web BrowserSending Requests to a Web Server
Web Server

hold/return static web pages

– e.g. index.html does not respond to user input.

Server Side Programs

different technologies written in various languages

 – e.g. CGI scripts, Java Servlets (and JSPs – later), PHP scripts
 – Call to http://localhost:8080/servlet/myhelloservlet.HelloServlet
 – Not web-browsing but executing program (servlet)
Dynamic response– database lookup, calculation etc.
We’ll look at the Java solutionhow to write servlets; how the container (Tomcat) works.

2. A general purpose Web Server

二、Simple Example

ignore how the Container finds the servlet (via the deployment descriptor web.xml).
<form action=“http://server.com/ExecuteServlet”>
<input type=“submit” value = “press for servlet”>
</form>

1.  A Basic Servlet

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import java.io.*;
//import jakarta.servlet.*:imports classes in this directory, but not in sub-directories
public class HelloServlet extends HttpServlet {
    public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
        response.setContentType("text/html");//设置响应文件类型、响应式的编码形式
        PrintWriter out = response.getWriter();//获取字符输出流
        out.println(“<html><body>Hello!</body></html>”);
        out.close();
    }
}

2.  Echo Servlet

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import java.io.*;
public class GetEchoServlet extends HttpServlet {
    public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException, ServletException {
        String userName = request.getParameter(“fname”);//获取form中输入的参数
        response.setContentType("text/html");//设置响应文件类型、响应式编码格式
        PrintWriter out = response.getWriter();//获取字符输出流
        out.println(“<html><body>Hello”);
        if (userName != null) 
            out.println(userName);
        else 
            out.println(“mystery person”);
        out.println(“</body></html>”);
        out.close();
    }
}

3. BMI Servlet

- HTML
//Page that asks for weight (kg) and height (cm) :Write the HTML and the HTTP Request (GET)
<form method=“GET”action=“http://server.com/BMIServlet”>
<input type=“text” name=“weight”/>weight<br>
<input type=“text” name=“height”/>height<br>
<input type=“submit” value=“send”>
</form>

- Servlet


import jakarta.servlet.*;
import jakarta.servlet.http.*;
import java.io.*;
public class BMIServlet extends HttpServlet {
    public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException {
        String ht = request.getParameter(“height”);
        int height = Integer.parseInt(ht);
        double weight = Double.parseDouble(request.getParameter(“weight”));
        double ht_squared = (height/100.0)*(height/100.0);
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println(“<html><body><br>”);
        out.println(“Your BMI is: ” + weight/ht_squared + “<body></html>”);
        out.close();
    }
}

4. Name-salary Servlet

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import java.io.*;
public class HelloServlet extends HttpServlet {
    public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
        String name = request.getParameter("name");
        int salary = Integer.parseInt(salary);
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<html><body><br>");
        out.println("Hello,"+name);
        out.println("Your salary is"+salary);
        out.println("<body><html>");
        out.close();
    } // end of method
} // end of class

三、Servlet Key Points

1. Servlets: Key points

NO main method public static void main(String[] args)
NO constructor

There is one (default) constructor but the developer should never write an explicit constructor

 – Why——servlet lifecycle

Two key (service) methodsdoGet(); doPost()

2. Finding things

Tracing the user data
– e.g. name attribute inside an HTML element
– name in HTTP request message
– argument in request.getParameter(...)
 String(int/double required)

then have to use appropriate method on this String to convert

- Integer.parseInt();

- Double.parseDouble();

Finding the servlet
<form> tag action attribute e.g. <FORM action=“servlet/myServlet” ...>
– Used by deployment descriptor, web.xml (see later), to map to the corresponding servlet class.

3. JavaBeans, JSPs and Servlets

Although a servlet can be a completely self-contained program, to ease server-side programming, generating content should be split into
The business logic (content generation), which governs the relationship between input, processing, and output.
The presentation logic (content presentation, or graphic design rules), which determines how information is presented to the user.
controllerthe servlet handles the HTTP protocol and coordination of which other servlets and auxiliary class methods to call
modelJava classes/JavaBeans handle the business logic
viewJava Server Pages handle presentation logic

4. Advantages of Servlets over CGI

Efficient
– Servlets run in the JVM. Each request is serviced using a thread rather than a new process (so lower overhead).
- Though some scripting languages, e.g. perl on certain web servers do this now.
Convenient– Provides infrastructure that parses and decodes HTML forms.
Powerful
– Can communicate directly with web server.
– Multiple servlets can share database connections.
– Simplifies session tracking.
Portable– Written in Java and follows standard API.
Secure
– CGI often executed using O/S shells, which can cause many security breaches.
– Array checking & exception handling is automatic in Java.
Inexpensive
– Many Java web servers are freely available.

四、Servlets in Detail

1. A general purpose Web Server

2. What servlets do

 requestRead any data sent by the user
Look up information embedded in HTTP request
Generate results.
response
Format results inside a document (e.g. HTML, XML, GIF, EXCEL).
Set appropriate HTTP response parameters.
Send the document back to the client.

3. Typical generic servlet code

import java.io.*;
import jakarta.servlet.*;
public class AnyServlet extends GenericServlet {
    public AnyServlet() {} 
        // constructor – BUT USE THE DEFAULT
        // NEVER ANY NEED TO WRITE ONE
        //ONLY creates an object, becomes a “proper” servlet after init().
    public void init(ServletConfig config) throws ServletException;
        // The method is actually called by container when servlet is
        // first created or loaded.
    public void service(ServletRequest req, ServletResponse res)throws ServletException, IOException;
        // Called by a new thread (in the container) each time a
        // request is received.
        public void destroy();
        // Called when servlet is destroyed or removed.
}

4. A Servlet is “deployed” in a container

• A program that receives (e.g. HTTP) requests to servlets from a web server application:
– finds the servlet (and loads, calls constructor & init() if not ready);
– creates or reuses a thread that calls service() method of chosen servlet;
– creates & passes request and response objects to chosen servlet;
– passes the response (e.g. HTTP response) back to the web server application; kills servlet thread or recycles into thread pool; and deletes request and response objects.
• More generally, manages the life cycle of its servlets:
Calls constructor, init(), service(), destroy().
– Also invokes methods of listening classes that a servlet implements (out of scope here).
• It has a main() and is working “all the time”.
• Also provides:
– Declarative security using settings in Deployment Descriptor (DD).
– JSP support.

5. Dissecting the Container’s actions

- HTTP request:
GET   /myServlet/BMIInfo   height=156&name=paula+fonseca   HTTP/1.1
- Servlet:
public class BMIServlet extends HttpServlet {
        public void doGet(HttpServletRequest request, HttpServletResponse response) throws
IOException, ServletException {
                // ...
                String ht = request.getParameter(“height”);
                // ...
        }
}

6. The servlet life cycle

7. methods & inheritance

8. Servlet’s Life cycle

Constructor (no arguments)
– not written or called by a developer
– called by the container
public void init()
– called after constructor
– called once, at the beginning (so potentially useful for initialisation of, e.g. databases)
– can be overridden by the developer
public void service(…)
rarely overridden by thedeveloper
– called everytime

public void doGet() /

public void doPost()

must be written by the developer
– must match the HTTP method in <form> in the HTML
public void destroy()

– must be written by the developer

五、 Configuration Servlets To Run In Tomcat

1. Mapping names using the Deployment Descriptor (DD)

//For each servlet in the web application.
//Internal name of servlet can be “anything” following XML rules.
<web-app ...>
    <servlet>
        <servlet-name>…</servlet-name>
        //maps internal name to fully qualified class name (except without .class)
        <servlet-class>…</servlet-class>
        //maps internal name to public URL name e.g. /makebooking
    </servlet>
    <servlet-mapping>
        <servlet-name>…</servlet-name>
        <url-pattern>…</url-pattern >
    </servlet-mapping>
...
</web-app>

2. Servlet Mapping Examples

- HTML:
<FORM method=“post” action=“/servlet/MyTest.do”>
- Server (webapps):
WEB-INF/classes/Echo.class
<servlet>
        <servlet-name>......</servlet-name>
        <servlet-class>.....</servlet-class>
</servlet>
<servlet-mapping>
        <servlet-name>......</servlet-name>
        <url-pattern>.......</url-pattern >
</servlet-mapping>
- HTML:
<FORM method=“post” action=“/servlet/Test”>
- Server (webapps):
WEB-INF/classes/foo/Name.class
<servlet>
        <servlet-name>......</servlet-name>
        <servlet-class>.....</servlet-class>
</servlet>
<servlet-mapping>
        <servlet-name>......</servlet-name>
        <url-pattern>.......</url-pattern >
</servlet-mapping>

3. Example: A Small Form

//SmallForm.html
<html>
    <title>Sending Form Information to a Servlet</title>
    <body>
        <form action="http://localhost:8080/servlet/elem004.ProcessSmallForm"method="post">
            //Can use absolute or relative URLs or pre-configured names.
            Please input your login: <br>
            <input type="text" name="Login">
            <input type="submit" value="Login">
        </form>
    </body>
</html>

//the Deployment Descriptor (web.xml) and the servlet
<servlet>
     <servlet-name>smallForm</servlet-name>
     <servlet-class>SmallFormServlet</servlet-class>
</servlet>
<servlet-mapping>
     <servlet-name>smallForm</servlet-name>
     <url-pattern>/servlet/elem004.ProcessSmallForm</url-pattern>
</servlet-mapping>

4. Putting everything in the right place

Level 1WEB-INF (folder) and .html, .jsp
Level 2(inside WEB-INF folder): web.xml and classes (folder)
Level 3 (inside classes folder): servlet .class files (and other “business” class files e.g. JavaBeans)

5. Servlet initialisation & Servlet Configuration object

• Only one servlet instance is created: each request is serviced by a separate thread in the container.
• Prior to initialisation, the ServletConfig object is created by the container:
– one ServletConfig object per servlet;
– container uses it to pass deploy-time information to the servlet (data you do not want to hard code into the servlet, e.g. the DB name);
– the names are specified in the DD.
• Parameters are set in a server-specific manner, e.g.
– in a file called web.xml (for Tomcat);
– in a file called resin.config (for Resin).
• Parameters do not change while servlet is deployed and running:
– like constants;
– if servlet changes, then need to redeploy.

6. Example: DD’s init parameters (web.xml for Tomcat)

<web-app xmlns=“http://java.sun.com/xml/ns/j2ee”
     xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
     xsi:schemaLocation=“http//java.sun.com/xml/ns/j2ee/web-app_2.4.xsd”
     version=“2.4”>
    <servlet>
        <servlet-name>Hello World Servlet</servlet-name>
        <servlet-class>S1</servlet-class>
        <init-param>
            <param-name>lecturersEmail</param-name>
            <param-value>paula.fonseca@qmul.ac.uk</param-value>
        </init-param>
        //Container reads these & gives them to ServletConfig object.
    </servlet>
</web-app>
out.println(getServletConfig().getInitParameter(“lecturersEmail”));
Returns the servlet’s ServletConfig object (all servlets have this method).
Getting a parameter value from the ServletConfig object; this code is in servlet.

7. Creating a servlet: ServletConfig and init(…)

Step 1container reads the deployment descriptor
Step 2container creates new ServletConfig object
Step 3
container creates name/value pair (Strings) for each servlet init-param
Step 4
container passes references to these to the ServletConfig object
Step 5container creates new instance of the servlet class
Step 6
container calls servlet’s init() method passing in reference to the ServletConfig object

六、Thread Safety And Putting Things Together

1. Instance Variables

public class ExampletServlet extends HttpServlet {
private int age;
public void init() { age = 0; }
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws
IOException, ServletException {
age = Integer.parseInt(request.getParameter(“age”));
response.setContentType(“text/html”);
PrintWriter out = response.getWriter();
out.println(“<HTML><BODY>You are ” + age + “ weeks old”);
out.println(“</BODY></HTML>”);
out.close();
}
}

2. The 3 Threads access same Resources

• We don’t know whose age will be displayed!
• Solution 1:
– Never use instance variables in servlets (some books say you
can’t – what they mean is you shouldn’t!).
– Find a way to save information (state) about each user (i.e.
each request) – we’ll see how later …
• Solution 2:
Synchronisation – a lock that makes a variable thread-safe

3. Access – introducing the ServletContext object

Servlet
ServletConfig object – one per servlet (or JSP)
– contains init params
– all requests made to a servlet can access this object
• Web application
ServletContext object – one per web application
• Web applications normally have several servlets/JSPs.
– Used to access web application parameters that need to be seen by all servlets/JSPs in the application.
• A misnomer, as it relates not to a servlet but to the set of servlets and JSPs in the web application.
The web application’s DD specifies the context parameters

<web-app ...> ...
    <servlet>
        <servlet-name>...</servlet-name>
        <servlet-class>...</servlet-class>
    <init-param>
        <param-name>...</param-name>
        <param-value>...</param-value></init-param>
    </servlet> ... + other servlets
    <context-param>
        <param-name>HOP_Email</param-name>
        <param-value>g.tyson@qmul.ac.uk</param-value>
    </context-param>
...
</web-app>

Note: Not inside any servlet. These are parameter namevalue pairs: both are strings.

ServletContext object created and set up when web application is deployed.

4. To access web app parameters in servlet code

ServletContext ctx = getServletContext();
out.println(ctx.getInitParameter(“HOP_Email”));
Context parameters generally more commonly used than Config.
– Typical use (of former) is a DB lookup name.
• Can access ServletContext,
– directly: getServletContext().getInitParameter(…)
– from ServletConfig: getServletConfig().getServletContext().getInitParameter(…)
– Latter is useful if in a method of an auxiliary class e.g. a JavaBean, and only the ServletConfig object has been passed as a parameter.
Same name for get method as when accessing ServletConfig object.

5. ServletContext also has attributes

• Parameters are name-value pairs, where both name and value are strings.
• Attributes are name-value pairs where the name is a String, but the value is an object (that may not be a String).
– accessed by getAttribute(String);
– set by setAttribute(String,Object).
• Running code prior to invoking any servlet in the application:
– E.g. to turn sets of parameters into attribute objects,
• so all servlets only need to deal with objects;
• and don’t have to read the context parameters.
– Implement a ServletContextListener (out of scope here)

6. Servlets – The Basics: Key Points & What we can’t do yet

How to call a servlet in an HTML formWhat a deployment descriptor does
How to write a servletWhere to deploy files
How to access client informationServlet life-cycle
Initialisation
ServletConfig
ServletContext
Have a conversation with a client
– Shopping basket
Session object
Run any code before a servlet starts
– E.g. Database set up
Listeners

Send client information, or control,

to another servlet/JSP

– Could be in another web server
Redirect and forward

7. Extracting unknown parameters and multiple values

String getParameter(String)
parameter name is known:
– returns null if unknown parameter;
– returns "" (i.e. empty string) if parameter has no value.
Enumeration getParameterNames() obtain parameter names
String[] getParameterValues(String) 

obtain an array of values for each one:

– returns null if unknown parameter;
– returns a single string ("") if parameter has no values. Case sensitive.

8. Example: A Big Form

//BigForm.html
<form action="http://localhost:8080/servlet/elem004.ProcessBigForm"method="post">
    Please enter: <br><br>
    Your login: <input type="text" name="Login"> <br><br>
    Your favourite colour:
    <input type="radio" name="Colour" value="blue">Blue
    <input type="radio" name="Colour" value="red">Red
    <input type="radio" name="Colour" value="green">Green <br><br>
    //Single-value parameters.
    Which of these courses you are taking: <br>
    <input type="checkbox" name="Course" value="elem001">ELEM001 <br>
    <input type="checkbox" name="Course" value="elem002">ELEM002 <br>
    <input type="checkbox" name="Course" value="elem003">ELEM003 <br>
    <input type="checkbox" name="Course" value="elem004">ELEM004 <br>
    <input type="submit" value="Send to Servlet">
    //Multiple-value parameter.
</form>
//After BigForm is processed.getParameterNames() returns parameters in no particular order.

//ProcessBigForm.java
//More code here ...
    out.println("<table border=1>");
    // Obtain all the form’s parameters from the request object.
    Enumeration paramNames = req.getParameterNames();
    while (paramNames.hasMoreElements()) {
        String paramName = (String) paramNames.nextElement();
        // Obtain values for this parameter and check how many there are.
        String[] paramValues = req.getParameterValues(paramName);
        if (paramValues.length == 1) { // a single value
            String paramVal = req.getParameter(paramName);
            out.println("<tr><td>" + paramName +"</td><td>"+ paramVal + "</td></tr>");
        }else { // If several values print a list in the table.
            out.println("<tr><td>" + paramName +"</td><td><ul>");
            for (int i = 0; i < paramValues.length; i++)
                out.println("<li>" + paramValues[i] + "</li>");
                out.println("</ul></td></tr>");
        }
    }
    out.println("</table>");
    out.close();
}

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Tekton — 通过tekton-operator部署tekton组件

文章目录 版本信息部署准备安装卸载tekton组件 Tektoncd Operator 作为一个 Kubernetes 的扩展&#xff0c;可以方便快捷地在 Kubernetes 集群上安装、升级和管理 Tekton Pipelines、Dashboard、Triggers 等组件。 那么本篇文章介绍在K8S集群中如何通过tekton-operator部署Tekt…

如何使用ArcGIS Pro进行坐标转换

不同来源的数据坐标系可能是不同的&#xff0c;为了统一使用这些数据就需要进行坐标转换&#xff0c;ArcGIS Pro作为专业的GIS软件&#xff0c;坐标转换功能肯定也是包含的&#xff0c;这里为大家介绍一下ArcGIS Pro如何进行坐标转换&#xff0c;希望能对你有所帮助。 数据来源…

OFI libfabric原理及应用解析

Agenda 目录/议题 编译通信软件硬件和软件带来的挑战为什么需要libfabriclibfabric架构API分组socket应用 VS libfabric应用区别GPU数据传输示例 编译通信软件 可靠面向连接的TCP和无连接的数据报UDP协议高性能计算HPC或人工智能AI 软硬件复杂性带来的挑战 上千个节点的集群, …

【算法-哈希表4】 三数之和(去重版)

今天&#xff0c;带来哈希相关算法的讲解。文中不足错漏之处望请斧正&#xff01; 理论基础点这里 三数之和 分析题意 这就是三数之和去重版嘛。 题意转化 求三元组, 满足每个元素相加为0&#xff0c;其中每个元素下标不同&#xff1b;而得到的三元组不能重复。 构成三元…

【20年扬大真题】删除字符串s中的所有空格

【20年扬大真题】 删除字符串s中的所有空格 代码思路&#xff1a; 可以定义一个辅助的字符数组tmp&#xff0c;一边遍历字符串s&#xff0c;一边用tmp暂存s中的非空格元素。 遍历完s之后&#xff0c;再把tmp中的元素赋给字符串s即可 #include<stdio.h> #define MaxSize…

栈和队列【详解】

目录 一、栈 1.栈的定义 2.栈的初始化 3.入栈 4.出栈 5.获取栈顶元素 6.获取栈元素的个数 7.判断栈是否为空 8.销毁栈 二、队列 1.队列的定义 2.入队 3.出队 4.获取队头元素 5.获取队尾元素 6.判断队列是否为空 7.获取队列的元素个数 8.销毁队列 前言&#xf…

el-input限制输入整数等分析

文章目录 前言1、在 Vue 中&#xff0c;可以使用以下几种方式来限制 el-input 只能输入整数1.1 设置input 的 type为number1.2 使用inputmode1.3 使用自定义指令1.4 使用计算属性1.5 使用 onafterpaste ,onkeyup1.6 el-input-number 的precision属性 总结 前言 input 限制输入…

python命令行交互 引导用户输入一个数字

代码 以下代码将在命令行中&#xff0c;引导用户选择一个数字&#xff0c;并反馈用户输入的值 # -*- coding:UTF-8 -*- """ author: dyy contact: douyaoyuan126.com time: 2023/11/22 15:51 file: 引导用户输入一个数字.py desc: xxxxxx """#…

D. Absolute Beauty - 思维

题面 分析 补题。配上题解的图&#xff0c;理解了很长时间&#xff0c;思维还需要提高。 对于每一对 a i a_i ai​和 b i b_i bi​&#xff0c;可以看作一个线段的左右端点&#xff0c;这是关键的一步&#xff0c;那么他们的绝对值就是线段的长度&#xff0c;对于线段相对位…

C++ MiniZip实现目录压缩与解压

Zlib是一个开源的数据压缩库&#xff0c;提供了一种通用的数据压缩和解压缩算法。它最初由Jean-Loup Gailly和Mark Adler开发&#xff0c;旨在成为一个高效、轻量级的压缩库&#xff0c;其被广泛应用于许多领域&#xff0c;包括网络通信、文件压缩、数据库系统等。其压缩算法是…

Doris数据模型的选择建议(十三)

Doris 的数据模型主要分为 3 类&#xff1a;Aggregate、Uniq、Duplicate Aggregate: Doris 数据模型-Aggregate 模型 Uniq&#xff1a;Doris 数据模型-Uniq 模型 Duplicate&#xff1a;Doris 数据模型-Duplicate 模型 因为数据模型在建表时就已经确定&#xff0c;且无法修改…

焦炉加热系统简述

烟道吸力 焦炉负压烘炉分烟道的吸力会影响立火道温度&#xff0c;具体影响因素如下&#xff1a; 烟道吸力过大会导致热量被抽走&#xff0c;使立火道温度降低。烟道吸力不足会导致烟气在烘炉内停留时间过长&#xff0c;使热量无法充分利用&#xff0c;也会导致立火道温度降低…

安防监控视频融合平台EasyCVR定制化页面开发

安防监控EasyCVR视频汇聚平台基于云边端智能协同&#xff0c;支持海量视频的轻量化接入与汇聚、转码与处理、全网智能分发、视频集中存储等。安防视频平台EasyCVR拓展性强&#xff0c;视频能力丰富&#xff0c;具体可实现视频监控直播、视频轮播、视频录像、云存储、回放与检索…

元素的点击操作

元素的点击操作 .click 语法 // 单击某个元素 .click()// 带参数的单击 .click(options)// 在某个位置点击 .click(position)// 在某个位置点击&#xff0c;且带参数 .click(position, options)// 根据页面坐标点击 .click(x, y)// 根据页面坐标点击&#xff0c;且带参数 .c…

冷链运输车辆GPS定位及温湿度管理案例

1.项目背景 项目名称&#xff1a;山西冷链运输车辆GPS定位及温湿度管理案例 项目需求&#xff1a;随着经济发展带动物流行业快速发展&#xff0c;运输规模逐步扩大&#xff0c;集团为了适应高速发展的行业现象&#xff0c;物流管理系统的完善成了现阶段发展的重中之重。因此&…

Elasticsearch:FMA 风格的向量相似度计算

作者&#xff1a;Chris Hegarty 在 Lucene 9.7.0 中&#xff0c;我们添加了利用 SIMD 指令执行向量相似性计算的数据并行化的支持。 现在&#xff0c;我们通过使用融合乘加 (Fused Mulitply-Add - FMA) 进一步推动这一点。 什么是 FMA 乘法和加法是一种常见的运算&#xff0c;…

echarts实现如下图功能代码

这里写自定义目录标题 const option {tooltip: {trigger: axis},legend: {left: "-1px",top:15px,type: "scroll",icon:rect,data: [{name:1, textStyle:{color: theme?"#E5EAF3":#303133,fontSize:14}}, {name: 2, textStyle:{color: theme…

超详细 | 实验室linux服务器非root账号 | 安装pip | 安装conda

登录实验室公用服务器&#xff0c;个人账号下&#xff08;非root&#xff09;是空的&#xff0c;啥也没有&#xff0c;想安装下pip和conda。 转了一圈&#xff0c;好像没太有针对这个需求写具体博客的&#xff0c;但有挺多讲直接在root下安的&#xff08;用的应该是个人虚拟机&…

【面试HOT300】滑动窗口篇

系列综述&#xff1a; &#x1f49e;目的&#xff1a;本系列是个人整理为了秋招面试的&#xff0c;整理期间苛求每个知识点&#xff0c;平衡理解简易度与深入程度。 &#x1f970;来源&#xff1a;材料主要源于【CodeTopHot300】进行的&#xff0c;每个知识点的修正和深入主要参…