Correct use posture of Request.getsession (Boolean create)

Source: Internet
Author: User

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)

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.