Detailed explanation and simple example of cookie in Java

Detailed explanation of cookies in Java

The operation of cookies in Java is relatively simple. It mainly introduces the establishment and reading of cookies, as well as how to set the life cycle of cookies and the path of cookies.

Create a non life cycle cookie, that is, a cookie that disappears as the browser closes. The code is as follows

Next, create a cookie with a life cycle to set its life cycle

The following describes how to read cookies. The code to read cookies is as follows

The above is the basic operation of reading and writing cookies. In practice, we'd better encapsulate it, such as adding a cookie. We focus on the name, value and life cycle of the cookie, so encapsulate a function and of course pass in a response object. The addcookie () code is as follows

When reading cookies, in order to facilitate our operation, we want to encapsulate a function. As long as we provide the name of the cookie, we can obtain the value of the cookie. With this idea, it is easy to think of encapsulating the cookie into the map, so we do the following encapsulation

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>