In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
What is the basis of cookies? I believe many inexperienced people are helpless about this. For this reason, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Cookie
A technique in which a server sends a small amount of information to a browser in the form of key-value pairs.
When the browser requests the server for the first time, the server will encapsulate a piece of information into a Cookie and send it to the browser. When the browser receives the Cookie, it will save it in memory (note that the memory here is local memory, not server memory) or a local file. After that, every time a request is sent to the server, the browser will carry the Cookie, and the server can process the business according to the information of the Cookie.
Disadvantages of cookies
Cookies increase network traffic because requests or responses are sent as messages.
Cookies are plaintext transmissions with poor security.
Each browser has restrictions on cookies and limitations on their use.
Creation of cookies
Create a Cookie object in Servlet and add it to Response.
Then open the browser to access the Servlet program, and the server sends Cookie information to the browser.
Cookies are automatically saved by the browser, and we can then read the Cookie information the next time the browser sends a request.
Cookie reading
Reading cookies mainly refers to reading cookies carried in browsers.
The server acquires the Cookie code passed by the browser: request.getCookies()
Traversing the Cookie array to get all Cookie information
How long cookies are valid
The Cookie instance method setMaxAge() controls how long a Cookie lives and receives an int parameter in seconds.
Parameter set to 0, that is: setMaxAge(0): immediately invalid, indicating that the browser will delete cookies as soon as it receives a response
Parameter setting is greater than 0: for example, setMaxAge(60), which indicates the number of valid seconds. After 60 seconds, the Cookie will expire.
Parameter setting is less than 0: for example setMaxAge(-1), indicating that the current session is valid. That is, after closing the browser, the Cookie expires and is deleted.
If no expiration time is set, the default is that the current session is valid. Once the browser is closed, the Cookie expires and is deleted.
After reading the above content, do you know what the basis of cookies is? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.