How to pass a “url with parameters” as a url parameter in GWT

gwturl-encoding

I am calling a servlet from GWT client code using RequestBuilder.

In the request (a POST) I am passing some request data

builder.sendRequest(postData, new RequestCallback()….

In the postData I have a url parameter called "returnToUrl"

This "returnToUrl" has url parameters, and would be like this

returnToUrl = "http://my.server/add?pn=a&pd=b";

When I pass it to the servlet, the second (and later) parameters (pd=b in my example) get interpreted as request parameters for the servlet, not as part of the returnToUrl parameter, and hence get lost….

It is being URL encoded, but of course that doesn't change the '?' and '&' characters.

Any help much appreciated!

Best Answer

You need to encode your data in GWT.

Take a look at the URL class to do this: http://google-web-toolkit.googlecode.com/svn/javadoc/2.4/com/google/gwt/http/client/URL.html

escpecially at encodeQueryString which basically has the same behaviour as encodeURIComponent in javascript.

Related Topic