What are the servlet conversation technologies?
This article mainly talks about "what are the servlet conversation technologies". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the servlet conversation skills"?
First, cookie session.
(1) create a Cookie
1. Create cookie
Cookie cookie=new Cookie ("name", "zhangsan"); / / Chinese is not allowed in cookie. If you need to put it in Chinese, you must encode it.
Cookie cookie=new Cookie ("name", java.net.URLEncoder.encode ("Zhang San", "utf-8"); / / Encoding
Java.net.URLDecoder.decode (cookie.getValue (), "utf-8") / / Decoding
two。 Set the lifecycle of cookie (seconds)
Cookie.setMaxAge (3600)
Cookie.setMaxAge (negative); / / the browser will expire when it is closed.
Cookie.setMaxAge (0); / / Delete this cookie
3. Write back the cookie information to the browser
Response.addCookie (cookie); / / this sentence is very important. Whenever you delete cookie.setMaxAge (0), you have to write back to the past.
(2) read Cookie
1. Read all cookie information
Cookie cookies [] = request.getCookie ()
two。 Benefit all the cookie
For (int iTuno Bandi)