12 servlet - session objects

session object

To pass information between the different requests from the same user session object used.

principle

The user first accesses the server, the server creates a session object to the user and JSESSIONID use cookie technology to store the session object to the browser, the request to ensure that other users can get to the same session object, but also to ensure that the different request to the shared data can be acquired.

Feature

  • Created on the server
  • In the server storage
  • Rely on cookie technology
  • A session (without closing the browser as a session)

use

Create session Object / Get session object (codes are used in the same sentence)

HttpSession hs = req.getSession();

  •   If there is a session identifier of the request is JSESSIONID, returns the corresponding session formation
  •   If the request does not indicate the session identifier is JESESSIONID, then create a new session object and JSESSIONID as a browser cookie data storage
  •   If the session object is invalidated, and will re-create a session object and JSESSIONID stored in browser memory

Setting Session Time

  hs.setMaxInactiveInterval(int seconds);

  Note: session object is not used within a specified time, then destroyed. If you use the re-timing.

Note: JSESSIONID a cookie is stored in temporary storage space, the browser is closed lapse.

 

Guess you like

Origin www.cnblogs.com/Scorpicat/p/12355595.html