当前位置:网站首页>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是服务端的存储机制

边栏推荐
- System design learning (I) design pastebin com (or Bit.ly)
- 165. Compare version number - string
- (超详细二)onenet数据可视化详解,如何用截取数据流绘图
- 9.指针(上)
- 2.C语言矩阵乘法
- Inheritance and polymorphism (I)
- arduino+水位传感器+led显示+蜂鸣器报警
- Summary of multiple choice questions in the 2022 database of tyut Taiyuan University of Technology
- There is always one of the eight computer operations that you can't learn programming
- Questions and answers of "basic experiment" in the first semester of the 22nd academic year of Xi'an University of Electronic Science and technology
猜你喜欢

系统设计学习(一)Design Pastebin.com (or Bit.ly)

5. Function recursion exercise

8. C language - bit operator and displacement operator

Abstract classes and interfaces

Quickly generate illustrations

图书管理系统小练习

西安电子科技大学22学年上学期《射频电路基础》试题及答案

(super detailed II) detailed visualization of onenet data, how to plot with intercepted data flow

arduino+水位传感器+led显示+蜂鸣器报警

12 excel charts and arrays
随机推荐
MySQL limit x, -1 doesn't work, -1 does not work, and an error is reported
系统设计学习(一)Design Pastebin.com (or Bit.ly)
Abstract classes and interfaces
First acquaintance with C language (Part 1)
C language to achieve mine sweeping game (full version)
Arduino+ds18b20 temperature sensor (buzzer alarm) +lcd1602 display (IIC drive)
View UI Plus 发布 1.3.1 版本,增强 TypeScript 使用体验
更改VS主题及设置背景图片
继承和多态(上)
Share a website to improve your Aesthetics
分支语句和循环语句
9.指针(上)
C语言入门指南
2. Preliminary exercises of C language (2)
3. C language uses algebraic cofactor to calculate determinant
1.C语言初阶练习题(1)
2-year experience summary, tell you how to do a good job in project management
FileInputStream和BufferedInputStream的比较
Change vs theme and set background picture
C语言实现扫雷游戏(完整版)