开发者

How should a GWT encoded query parameter be decoded server side?

开发者 https://www.devze.com 2023-03-08 06:31 出处:网络
I\'m encoding a query parameter using GWT\'s com.google.gwt.http.client.URL.encode() method, but have found I ca开发者_Python百科n\'t use URL.decode() on the server to decode it because the implementa

I'm encoding a query parameter using GWT's com.google.gwt.http.client.URL.encode() method, but have found I ca开发者_Python百科n'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?


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


java.net.URLDecoder is implemented on AppEngine and works perfectly with com.google.gwt.http.client.URL.encode().


If you're not willing to use gwt-rpc you can encode/decode with Base64. Check this link for a gwt implementation of the Base64 encoder/decoder. Then all you have to do is Base64.encode(yourParameterValue) before sending the request to the server and Base64.decode(request.getParameter(yourParameterName)) on the backend right after receiving the request.

cheers!

0

精彩评论

暂无评论...
验证码 换一张
取 消