当前位置:网站首页>Web Security (VI) the use of session and the difference between session and cookie
Web Security (VI) the use of session and the difference between session and cookie
2022-07-06 05:28:00 【jinyangjie0】
Session It's a conversation , It is a data structure used to record user information on the server .
Session Use
1、 obtain Session object
HttpSession s = request.getSession(boolean flag);
notes :HttpSession It's an interface .
When flag by true when , According to the SessionId Find corresponding Session object , If it does not exist, return to new Session object .
When flag by false when , Also according to the request SessionId Find corresponding Session object , Returns if it does not exist null.
2、 Common methods
Data binding :
session.setAttribute(String name,Object obj);
Get the binding value according to the binding name :
Object session.getAttribute(String name);
Unbind :
session.removeAttribute(String name);
3、Session Automatic destruction of
Tomcat Server default Session The timeout is 30 minute
You can use web.xml Set the timeout in minutes , Set to 0 Indicates not to destroy .
<session-config> <session-timeout>20</session-timeout> </session-config>
Session And Cookie The difference between
solve HTTP The stateless ways of the agreement itself are cookie and session. Both can record the status , The former is to save the state data on the client , The latter is saved on the server .
Session How it works
session The basic principle of is that the server is for each session Maintain a copy of session information data , The client and server rely on a globally unique identity to access the session information data . User access web When applied , The server program decides when to create session, establish session It can be summed up in three steps :
1、 Generate globally unique identifier (sessionid);
2、 Open up data storage space . Generally, the corresponding data structure will be created in memory , But in this case , Once the system is powered down , All session data will be lost , If it's an e-commerce website , This kind of accident will have serious consequences . But it can also be written to a file or even stored in a database , Although this will increase I/O expenses , but session Some degree of persistence can be achieved , And it's better session The share of ;
3、 take session Send the globally unique identifier of to the client .
Cookie How it works
No matter what server-side technology is used , Just send back HTTP The response contains a header in the form of , It is considered that the server requires a cookie:
Set-cookie:name=name;expires=date;path=path;domain=domain
Support cookie All browsers will respond to this , creating cookie File and save ( It could also be memory cookie), Every time the user sends a request in the future , The browser should judge all the current cookie There is no failure in ( according to expires Attribute judgment ) And it matches path Attribute cookie Information , If any , It will be added to the request header and sent back to the server in the following form :
Cookie: name=“zj”; Path="/linkage"
The dynamic script on the server side will analyze it , And make corresponding treatment , Of course, you can also choose to ignore .
It should be noted that , For security reasons ,cookie Can be disabled by the browser .
边栏推荐
- First acquaintance with CDN
- Cuda11.1 online installation
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- LeetCode_ String inversion_ Simple_ 557. Reverse word III in string
- Nacos - TC Construction of High available seata (02)
- Vulhub vulnerability recurrence 68_ ThinkPHP
- 注释、接续、转义等符号
- Principle and performance analysis of lepton lossless compression
- Configuration file converted from Excel to Lua
- flutter 实现一个有加载动画的按钮(loadingButton)
猜你喜欢

Deep learning -yolov5 introduction to actual combat click data set training

Using stopwatch to count code time

Vulhub vulnerability recurrence 69_ Tiki Wiki

C Advanced - data storage (Part 1)
![[leetcode daily question] number of enclaves](/img/6e/1da0fa5c7d1489ba555e4791e2ac97.jpg)
[leetcode daily question] number of enclaves

Cve-2019-11043 (PHP Remote Code Execution Vulnerability)

28io stream, byte output stream writes multiple bytes

Promise summary

GAMES202-WebGL中shader的編譯和連接(了解向)

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
随机推荐
备忘一下jvxetable的各种数据集获取方法
LeetCode_字符串反转_简单_557. 反转字符串中的单词 III
趋势前沿 | 达摩院语音 AI 最新技术大全
Vulhub vulnerability recurrence 71_ Unomi
27io stream, byte output stream, OutputStream writes data to file
Oracle query table index, unique constraint, field
Mysql高级篇学习总结9:创建索引、删除索引、降序索引、隐藏索引
Cve-2019-11043 (PHP Remote Code Execution Vulnerability)
Algorithm -- climbing stairs (kotlin)
【LeetCode】18、四数之和
[QNX Hypervisor 2.2用户手册]6.3.3 使用共享内存(shmem)虚拟设备
Modbus protocol communication exception
[effective Objective-C] - memory management
Golang -- TCP implements concurrency (server and client)
01. Project introduction of blog development project
In 2022, we must enter the big factory as soon as possible
无代码六月大事件|2022无代码探索者大会即将召开;AI增强型无代码工具推出...
SQLite queries the maximum value and returns the whole row of data
毕业设计游戏商城
Qt TCP 分包粘包的解决方法