当前位置:网站首页>Cookie和Session的区别
Cookie和Session的区别
2022-07-06 09:20:00 【快醒醒鸭今天你编程了吗?】
Cookie:是客户端浏览器用来保存服务端数据的一种机制,当通过浏览器进行网页访问的时候服务器可以把某一些状态数据以key-value的形式写入到Cookie里存储到客户端浏览器里面,然后客户端下一次再访问服务器的时候就携带这些数据发送到服务器端,服务器可以根据Cookie里面携带的内容去识别
Session:表示会话属于服务器端的一个容器对象默认情况下他会针对每一个浏览器的请求,Servlet容器都会分配一个Session对象,Session的本质可以认为是一个ConcurrentHashMap它可以用来存储当前会话产生的一些状态数据,Http本身是一个无状态的协议,也就是说服务器端并不知道客户端发送过来的多次请求是属于同一个用户的,所以Session是用来弥补Http无状态的一个不足。
简单来说服务器端可以利用Session来存储客户端在同一个会话里面产生的多次请求的一个记录那么基于服务器端的Session的存储机制再结合客户端的Cokkie机制我们就可以实现一个有状态的Http协议
工作原理:
客户端第一次访问服务器端上的时候,服务器端会针对这次请求创建一个会话并且生成一个唯一的SessionID来标注这个会话,然后服务器端把这个SessionID写入到客户端浏览器的Cookie里面,用来实现客户端状态的一个保存,在后续的请求里面每一次都会携带SessionID,服务端就可以根据这个SessionID来识别当前这个会话的状态。
总的来看Cookie是客户端的存储机制,而Session是服务端的存储机制
边栏推荐
- Database operation of tyut Taiyuan University of technology 2022 database
- MySQL limit x, -1 doesn't work, -1 does not work, and an error is reported
- 3. Number guessing game
- Atomic and nonatomic
- Tyut Taiyuan University of technology 2022 "Mao Gai" must be recited
- (ultra detailed onenet TCP protocol access) arduino+esp8266-01s access to the Internet of things platform, upload real-time data collection /tcp transparent transmission (and how to obtain and write L
- TYUT太原理工大学2022数据库题库选择题总结
- TYUT太原理工大学2022“mao gai”必背
- Introduction pointer notes
- Tyut Taiyuan University of technology 2022 introduction to software engineering
猜你喜欢
西安电子科技大学22学年上学期《信号与系统》试题及答案
1. C language matrix addition and subtraction method
12 excel charts and arrays
1.C语言矩阵加减法
TYUT太原理工大学2022“mao gai”必背
抽象类和接口
Counter attack of flour dregs: redis series 52 questions, 30000 words + 80 pictures in detail.
Tyut Taiyuan University of technology 2022 "Mao Gai" must be recited
Decomposition relation model of the 2022 database of tyut Taiyuan University of Technology
MYSQL索引钟B-TREE ,B+TREE ,HASH索引之间的区别和应用场景
随机推荐
(超详细二)onenet数据可视化详解,如何用截取数据流绘图
Arduino+ds18b20 temperature sensor (buzzer alarm) +lcd1602 display (IIC drive)
Introduction and use of redis
MySQL Database Constraints
[while your roommate plays games, let's see a problem]
初识C语言(下)
167. Sum of two numbers II - input ordered array - Double pointers
继承和多态(上)
六种集合的遍历方式总结(List Set Map Queue Deque Stack)
MySQL 30000 word essence summary + 100 interview questions, hanging the interviewer is more than enough (Collection Series
vector
西安电子科技大学22学年上学期《信号与系统》试题及答案
3. Number guessing game
View UI plus released version 1.3.0, adding space and $imagepreview components
C语言实现扫雷游戏(完整版)
2. Preliminary exercises of C language (2)
最新坦克大战2022-全程开发笔记-3
Alibaba cloud microservices (IV) service mesh overview and instance istio
Abstract classes and interfaces
2.初识C语言(2)