0

I am making a web app which uses RPC as the main communication mechanism between my client and server. One thing I want to do is to prevent a user opening my web app in multiple browser tabs. So I want to assign some tab id based on the login time.

Unfortunately, it is not as simple as I expected. First of all, I do not know how to set cookies from my rpc servelet (RemoteServiceServlet) to the client's browser. I am not sure whether it is doable. If not, I hope there is a way to pass the cookie to the client by modifying the HttpServeletResponse. (I do not want to mix this cookie with my returning data.) Furthermore, how can I get the Response object from client side?

Any help will be appreciated.

EDIT:

I tried to set some cookies in the HttpServletResponse which I got from calling getThreadLocalResponse() But I cannot get them from the client side. Cookies.getCookie(xxx) always returns null.

Alex
  • 2,915
  • 5
  • 28
  • 38
  • Did you check this thread (http://stackoverflow.com/questions/15045431/sessions-and-cookies-to-autologin-in-gwt)? Especially this link: https://varuntayur.wordpress.com/2012/01/25/session-management-in-gwt/ – rsutormin Sep 10 '15 at 03:38

1 Answers1

1

To access the HttpServletResponse from your RemoteServiceServlet, just call getThreadLocalResponse() (same is available for the request too).

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • Seems like the HttpServletResponse I got from calling getThreadLocalResponse() is not the same as the one returning to the client. I set some cookies in the HttpServletResponse, but I cannot get it from the client side. Cookies.getCookie(xxx) always returns null. – Alex Sep 10 '15 at 18:23