URLEncode in GWT?

517 views
Skip to first unread message

devonianfarm

unread,
Jun 21, 2007, 3:15:46 PM6/21/07
to Google Web Toolkit
I am writing a GWT app that generates URLs, often of a format like

something.html?id=arbitrary_parameter

I'd like to run "arbitrary_parameter" through something like the
URLEncode.encode() function so that I know the app produces safe
URLs. URLEncode is in java.net, so, according to the
documentation, it's not available in GWT. Is this correct? Is there
an alternative function to do this? Or do I need to code up my own
encoder?

Ian Petersen

unread,
Jun 21, 2007, 3:22:41 PM6/21/07
to Google-We...@googlegroups.com
I don't know if there's a more GWT-ish way to do this, but you can use
the native Javascript encodeURIComponent() function via JSNI:

public class MyUtilityClass {

public static native void encodeURIComponent(String component) /*-{
return encodeURIComponent(component);
}-*/;
}

Ian

--
Tired of pop-ups, security holes, and spyware?
Try Firefox: http://www.getfirefox.com

Robert Hanson

unread,
Jun 21, 2007, 3:27:15 PM6/21/07
to Google-We...@googlegroups.com
This is available in the HTTP module, you need to add this import to your module config:

<inherits name="com.google.gwt.http.HTTP"/>

Then use URL.encode();

Docs: http://code.google.com/webtoolkit/documentation/com.google.gwt.http.client.URL.html


Rob

devonianfarm

unread,
Jun 21, 2007, 3:53:52 PM6/21/07
to Google Web Toolkit
Thanks!

Reply all
Reply to author
Forward
0 new messages