Servlet - Cookie related

/ * 

1. role: to solve the data sharing request sent different question 

2. Features: browser-side data storage technology, data declarations stored on the server side 

using 3 

    1. Create a Cookie object 
        Cookie cookie = new Cookie ( "key "," value "); 
        
    2. set valid Cookie objects 
        cookie.setMaxAge (int); 
        
        Cookie storage divided into two types: 
        temporary storage: stored in the memory to run the browser, the browser is closed shall lapse, created by default Cookie way is temporarily stored in 
        the timing storage: in the creation of Cookie objects can set the validity period of Cookie objects 
                    timing storage of Cookie stored in the client's hard drive, in the period, 
                    in line with the path requirements of the request will be included with the information 
        
        
    3. set Cookie object effective path 
        cookie.setPath (uri); 
        
        By default, Cookie information stored after a good, every time a request comes 
        if a valid path Cookie settings, then the only access route when set, will be incidental Cookie information 
        
    4. Cookie added to the appropriate object 
        response.addCookie (cookie);
        
        Cookie object store a piece of data, a plurality of data can create several multi-Cookie objects stored 
        
    5. Obtain Cookie object 
    
        // array of objects acquired Cookie request object 
        Cookie [] = Cookies request.getCookies (); 
    
        // iterate Cookie array, each acquiring cookie object 
        for (cookie cookie: cookies) { 
            the Cookie.getName (); // Get the cookie Key 
            cookie.getValue (); // Get the cookie value 
        } 

* /

 

Guess you like

Origin www.cnblogs.com/mpci/p/12632583.html