Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

request.getSession() vs getThreadLocalRequest().getSession()

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.

like image 751
benstpierre Avatar asked Jun 02 '11 22:06

benstpierre


People also ask

What is the difference between request getSession () and request getSession true?

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.

What is request getSession ()?

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.

What is the use of HttpSession session request getSession false?

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.


1 Answers

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.

like image 168
Abdullah Jibaly Avatar answered Oct 10 '22 02:10

Abdullah Jibaly