session related

session to learn:
* Question:
* Different user requests need to use data from other requests when dealing with how to do?
* Fix:
* Technical session
* Use:
* Create a session object
* the HttpSession session = the req.getSession ();
* data is stored in the session
* session.setAttribute (String name, Object value);
* Gets the session object
* HttpSession session = req .getSession ();
* get data session in the
* session.getAttribute (String uname); Note: object type back, you need to cast
* delete the data session in the
* session.removeAttribute (String uname); Note: If you have data is removed, there is nothing to do.
* Process:
* 1, the browser initiates a request to Aservlet, use req.getSession in AServlet in () Gets Session object, if the request is not
* SessionID create a new Session object, if there will be corresponding SessionID session object returns (provided that the session object does not expire), if session
* Object expire destroyed, even if there sessionID will re-create a Session.
* 2, check whether the session fails, the data is stored into the session object or get the data session in the session or delete data
* Features:
* session to solve the problem of sharing data with a different requesting user.
* Session scope: the browser is not closed, session does not fail, then any request to obtain the same user are the same the session
* first session
* session settings:
* session valid default time is 30 minutes, you can under the tomcat configure the web.xml
* NOTE: this configuration under all project tomcat default is 30 minutes
* can also be used in code
* session.setMaxInactiveInterval (int seconds); // set the session valid time, parameters integer types seconds
* session.invalidate (); // force the destruction of session

Guess you like

Origin www.cnblogs.com/LuJunlong/p/12359011.html