There is a way to create session sessions in Javax.servlet.http.HttpServletRequest
/**
* If Create is set to True, returns the current httpsession, if there is no session, a new session is created
* If Create is set to False, returns if there is a current session and returns NULL if there is no session
*/
Public HttpSession getsession (Boolean create);
/**
* Equivalent to GetSession (true);
*/
Public HttpSession getsession ();
Key points of Use:
1. Create a session scene
This logic is placed in the login, authorization business, after the successful user login, it is natural to maintain the user's current access session.
Use GetSession (true) at this time, or getsession (), and the session can be placed into the specific attribute, which describes the current user sessions in more detail.
2. Find current session
If our current logic requires a lookup session, if the session is empty, the direct throw session does not exist, and the insufficient permissions information.
The GetSession (false) is used to find the current session, and no session is returned as NULL. Avoids the use of getsession () and creates a redundant, unauthorized session.
Use GetSession (false) to get the current session, then get the current attribute, and do the next business processing.
Complete the full text.
Correct use posture of Request.getsession (Boolean create)