NRJ
NRJ

Reputation: 1204

RemoteServiceServlet is returning null with getThreadLocalRequest()

I have this line in the constructor of my RemoteServiceServlet

userID = getThreadLocalRequest().getRemoteUser();

but its throwing NullPointerException because getThreadLocalRequest returns null.

My understanding was that RemoteServiceServlet inherits from HttpServlet and hence should have the HttpReuest object already !! Do I need to set anything before calling getThreadLocalRequest() in case of GWT?

Upvotes: 0

Views: 614

Answers (1)

David Levesque
David Levesque

Reputation: 22451

The problem could be that you are trying to use that method inside the constructor of a servlet. A new servlet instance is not created for each request. Servlet instances are reused across requests. Try calling getThreadLocalRequest() inside a service method instead.

Upvotes: 2

Related Questions