Cookie&&session

Source: Internet
Author: User

Session Technology
* Cookies: Save data to the client browser
* Session: The data white village to the server side
The use of cookie technology;
* Save data to Browser
* HttpServletResponse There's a way
* Vaid Addcookie (cookie cookie);------Response.addcookie (cookie);
* Get cookies brought by the browser
* HttpServletRequest There's a way
* cookie[] getcookies ();
* Create a Cookie Object
* New Cookie (String name,string value);
* Common API for Cookies
* GetName ();
* GetValue ();
* Serdomain (String domain): Set a valid domain name for the cookie,
* SetPath (PATH):: Set a valid path for the cookie
* Setmaxage (int maxAge); : Set the effective duration of the COO grams
* Classification of cookies
* Reply-level cookie: Default cookie, close browser cookie will be destroyed
* Persistent Cookie: You can set a cookie's effective time, then close the browser cookie will also exist, manually destroy the persistence cookie.setmaxage (0);---Prerequisite valid paths must be consistent

Overview of JSP;
* You want to export the form in a Dynamic Web page. Get PrintWriter out in servlet = Response.getwriter ();
* OUT.PRINTLN ("<form action=" method= ">");
* OUT.PRINTLN ("</form>");
* <%! %> <%%> <%=%>

* Overview of Session
* * The cookie itself is limited in size and number. There is no limit to the session. Cookie data white exists client, session data white exists server side
* Principle of Session execution
* Use session
* Get session
* Request.getsession ();
*session is a domain object
* When the session is created and destroyed:
* Create: Server-side First XI calls GetSession () to create a session;
* Destruction: Three kinds of cases destroyed session
* 1,session expires, default is 30 minutes
* 2, sub-normal shutdown server, if normal shutdown session serialized to hard disk
* Manual Call Session.incalidate (); Close method;
* Scope: Multiple requests (one session);


Teacher Summary
Cookie: Is the session technology that saves data to the client browser.
* Get Cookie:request.getCookies () from the browser;
* Write back Cookie:response.addCookie (cookie cookie) to the browser;
* Cookie-related APIs:
* SetPath (String path); --/DAY11/DAY11/AAA
* Setmaxage (int time); -Effective duration.
* SetDomain (String domain);
* Classification of cookies:
* Session Level Cookie: Session level when the browser is closed, the cookie is destroyed. Default
* Persistent level Cookie: Set a cookie that is valid for a length of time and will not be destroyed when the browser is closed.

Session: This is the conversation technology that saves the data to the server side. Based on cookie writeback SessionID.
* Session Access data:
* SetAttribute (String name,object value);
    * getattribute (String name);
* session scope:
    * The scope of  session: one session. (Multiple requests)
    * session life cycle:
        *  Create: The session is created the first time you call getsession.
        *  destroyed:
             *  shut down the server properly.
              * session expires
              *  manually calling the Invalidate method

Cookie&&session

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.