3

Is it the only way that making an RPC call in GWT for getting HTTP session attributes ?

Is there any way to get them directly in the client side code without making an rpc call ?

If browser is maintaining session why we need to go to the server again for a session variable?

Jama A.
  • 15,680
  • 10
  • 55
  • 88

6 Answers6

3

Is it the only way that making an RPC call in GWT for getting HTTP session attributes ?

For getting session attributes you can use different approach (for example with JSON). GWT-RPC is just one mechanism for passing Java objects to and from a server over standard HTTP. Read this article: Communicating with the server.

is there any way to get them directly in the client side code without making an rpc call ?

Shortly, no you cannot access them unless you retrieve them from server. Because all GWT applications run as JavaScript code in the end user's web browser, but the session lives in the server side. So you have to ask them from your server.

If browser is maintaining session why we need to go to the server again for a session variable ?

You have a wrong perception about sessions, they are not maintained by your browser. For controlling the session you have to call to the server-side with asynchronous callbacks or with another technique. Or if you mean Client side web sessions, you can control them with Cookies.

Jama A.
  • 15,680
  • 10
  • 55
  • 88
1

The browser doesn't have the session variables! All it has is the session identifier (which is usually kept in a cookie).

Chris Lercher
  • 37,264
  • 20
  • 99
  • 131
0
HttpSession session = RemoteServiceUtil.getThreadLocalRequest().getSession();
swamy
  • 1,200
  • 10
  • 23
0

I think you may just want to set cookie values to match some of your session values. You can do this at authentication time and set cookie values using the

public boolean authentication() {
   // Do authentication stuff
   getResponse().addCookie(new Cookie("SOMESESSIONID", session.getId()));
}

public HttpServletResponse getResponse() {
    return RemoteServiceUtil.getThreadLocalResponse();
}

Then on the client side you can simply use the Cookie class to fetch these values.

Chris Hinshaw
  • 6,967
  • 2
  • 39
  • 65
  • My original code was for RequestFactory so it looked like this. RequestFactoryServlet.getThreadLocalRequest(); – Chris Hinshaw Sep 05 '12 at 12:50
  • what i am doing is i am setting user bean in servlet and in GWT onmodule load i need that bean for furthur use ...now i am getting that using RPC and for RPC its taking too much time .So i want to remove an rpc call –  Sep 05 '12 at 13:23
0

Session is only available at server side and GWT compiles java in Js so we can not have session avilable at client side.

Manish Prajapati
  • 392
  • 2
  • 11
-1

Read the google group post - Synchronous Call

GWT does not make any effort to allow you to do it easily. You'd have to write your own extension of the RequestBuilder that allows Synchronous requests.

The problem with Synchronous requests is that they tend to block the browser waiting for a response, giving your application the appearance of being locked up. This is particularly bad application design. You have no control of the client machine or the network between it and your servers, and as such can't even dictate how long your application is going to appear locked.

So, the best idea is to simply use the asynchronous method and continue execution via the callbacks provided. You will end up with a much better user experience, and a more professional appearing application.

prayagupa
  • 30,204
  • 14
  • 155
  • 192