What is the difference between
request.getSession()
and
getThreadLocalRequest().getSession()
The application I am maintaining appears to use the first for straight Servletsand the second for anything implemented via GWT-RPC which itself extends servlet.
Calling getSession() and getSession(true) are functionally the same: retrieve the current session, and if one doesn't exist yet, create it. Calling getSession(false), though, retrieves the current session, and if one doesn't exist yet, returns null.
getSession() returns the valid session object associated with the request, identified in the session cookie that is encapsulated in the request object. Calling the method with no arguments creates a session if one does not exist that is associated with the request.
If you would like to ensure that a new session object is not created by default, you can use the second form of the method: HttpSession session = request. getSession(false); If the session does not already exist, getSession(false) returns null.
They both return the same thing. GWT simply stores the request sent in from the servlet into a thread local so that you don't need to pass it around in every method call and still have a separate request
for each invocation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With