How should a GWT encoded query parameter be decoded server side?
Solution 1
I solved my problem this way: on the client side, I encode the parameters using com.google.gwt.http.client.URL.encodeQueryString(), like:
URL.encodeQueryString(param)
On the server side, I get the parameters using the ServletRequest methods, like:
String myParam = req.getParameter("myparam");
PS I initially +1'd Riley Lark's answer, but then I got some problems with some characters too... Letting the ServletRequest do the job will handle all character's encoding for you. See Decoding international chars in AppEngine
Solution 2
java.net.URLDecoder
is implemented on AppEngine and works perfectly with com.google.gwt.http.client.URL.encode().
Comments
-
Alex Worden almost 2 years
I'm encoding a query parameter using GWT's com.google.gwt.http.client.URL.encode() method, but have found I can't use URL.decode() on the server to decode it because the implementation isn't available (I suspect it uses the javascript client side implementation). I get...
java.lang.UnsatisfiedLinkError: com.google.gwt.http.client.URL.decodeImpl(Ljava/lang/String;)Ljava/lang/String;
Can someone suggest what I'm supposed to use server side to decode the encoded string?
-
Alex Worden almost 13 yearsHi, It's not that I'm not willing to use gwt-rpc. Of course I'm using that everywhere in my app. In this case I've written some functionality that allows a user to request a file from the server which is delivered as an appropriate mime type etc... I need to pass query parameters in the request. Thanks for the Base64 encoder tip! We ended up writing our own common encode / decode functionality since the GWT encode doesn't work correctly (it doesn't encode a percent symbol!) and there's no guarantee it works correctly with the java URLDecode equivalent (mute point since it's broken anyway!)
-
Alex Worden almost 13 yearscom.google.gwt.http.client.URL.encode() doesn't work correctly. I know for a fact that it doesn't encode a percent symbol. I have no faith that it works in conjunction with the unrelated java.net.URLDecoder so I'm using some home-baked common encode / decode functionality available on both the client and server.
-
Riley Lark almost 13 yearsYou asked what you could use with URL.encode(), and URLDecoder is the answer. I think you should accept this answer as the most straight-forward. As an aside, URL.encode() is implemented with the browser's javascript implementation of encodeURI, and at least in my tests in Chrome and Firefox the
%
character is encoded to%25
. -
Lucas de Oliveira almost 13 yearsNot sure if it's a good idea to develop your own [de]coder as Base64 it's in agreement with many RFC's (in fact it's defined on the RFC 4648 - en.wikipedia.org/wiki/Base64#RFC_4648) but unfortunately is not implemented in GWT (not in 2.0.3 AFAIK). We've been using the Base64 [de]coder in all requests that are not gwt-rpc and they're working flawlessly so far.
-
Alex Worden almost 13 yearsIt's a safer bet to write your own that to attempt to mix'n'match two completely different implementations! :)
-
Alex Worden almost 13 yearsSorry - your solution did not work for me. The two implementations are not compatible in my tests.