GWT Tip: No Cookies Support

by Robert Cooper

Bruce from the Red Pill team at Google spoke to the Atlanta Java User's Group tonight and a question came up that I feel is important:

Q: I work for a guvment website, and we are forbidden by policy from using cookies. How do I maintain auth in my GWT web service.

A: The easy answer is to use a Dictionary class.

The Dictionary class is part of the i18n GWT package, but the big advantage it has is that it is resolved at runtime, rather than compile time. This means you can pass in values to your GWT app from the host page. In this case, the host page being a JSP.

What you want to do is create a script tag in a host JSP like this:

var services = {
service1 : "<%=response.encodeUrl( "[serviceURL1]") %>",
service2 : "<%=response.encodeUrl( "[serviceURL2]") %>"
}


That means you can now use :

Dictionary services = Dictionary.getDictionary("services")

to get a lookup for your service URLs with JSessionID encoded and use that when you construct your stubs. This will give the service cals the same JSessionID as your JSP host page.


7 Comments


2007-02-21 21:11:58
Rob,


How to post articles here on onJava.com? Thanks.

oneUser
2007-02-21 21:13:23
I wanted to know too.
oneUser
2007-02-23 14:22:37
Any replies, please?
oneUser
2007-02-23 19:41:04
anyone?
cooper
2007-02-24 16:22:35
It is a "be invited by O'Reilly" thing. I am honestly not sure who you would ask.
OneUser
2007-03-04 11:26:33
Thanks Rob. But how you got invited? Do you need to apply for it or after several posts, you were approached passively by editors from onjava?


Thanks in advance for any reply.

quinisha
2007-09-11 10:21:43
unblock