Request.getSession () vs getThreadLocalRequest (). getSession ()

What's the difference between

request.getSession() 

and

 getThreadLocalRequest().getSession() 

The application that I support seems to use the first for direct Servlets, and the second for anyone implemented through GWT-RPC, which itself extends the servlet.

+4
source share
4 answers
They both return the same. GWT simply saves the request sent from the servlet to the local stream, so you do not need to pass it in all method calls and still have a separate request for each call.
+6
source

getThreadLocalRequest () is a convenient way to get an HttpServletRequest.

Both methods request.getSession () and getThreadLocalRequest (). getSession () returns the same HttpSession, the difference is how you get the HttpServletRequest.

+3
source

The main reason is that you use your own RPC methods in your GWT servlet that do not receive HTTPRequest as a parameter - unlike the standard servlet methods doGet(...) , ..., doXYZ(...) . Thus, the only way to access HTTPRequest is with the getThreadLocalRequest() GWT RemoteServiceServlet provided, which you usually should distribute.

+2
source

The difference is the region. In particular, the request variable is available only directly from the areas of doGet(..) , doPost(..) , etc. (Inside the methods). After the thread you are in displaces the method and enters your biz doSomething() method, etc., your code no longer has access to the request variable (scope changed), but getThreadLocal..() allows you to get access regardless of the method you are in, given that you are in the same thread as doGet() , etc.

+2
source

All Articles