One way to solve the stateless http characteristics of session

the role of the session:
// session is a kind of user information stored on the server side technology

session definition:
// session: indicates that a user across multiple pages, and you can save some of the information to the user


//1.session create or obtain the current the session
the HttpSession request.getSession the session = ();


// the session's ID, is the only
System.out.println (session.getId ());


//2.session there is a maximum inactivity time
// If you do not set a maximum time of inactivity, the system defaults to 30 minutes
session.setMaxInactiveInterval (10); // 10s

. // 3 immediately destroy the session
session.invalidate ();


//4.session settings and saves the user information
session.setAttribute ( "name", "zhangsan");
session.setAttribute ( "Age", "22 is");
session.setAttribute ( "Gender", "M");

Outputs the corresponding information to the console
System.out.println (session.getId ());
System.out.println (session.getAttribute ( "name"));
System.out.println (session.getAttribute ( "Age") );
System.out.println (session.getAttribute ( "Gender"));


Note:
the session ID that is stored in a cookie, if you close your browser, it will be released, that is, the user can not find the information, of course, can not find in other browsers.

Guess you like

Origin www.cnblogs.com/su-chu-zhi-151/p/11199376.html
Recommended