How to read url info in gwt

119 views
Skip to first unread message

ake...@gmail.com

unread,
Jul 18, 2006, 11:09:18 PM7/18/06
to Google Web Toolkit
New to gwt. Would like to read url info (client-side) such as server,
page, & request parameters, but I don't see any classes/methods
specifically designed for this. Is there a simple way to do this?

IamRobe...@gmail.com

unread,
Jul 19, 2006, 7:44:03 AM7/19/06
to Google Web Toolkit
Check out the WindowUtils and Location classes in the GWT Widget Lib
(http://gwt-widget.sourceforge.net). They give you access to the
browser location object.

Here is the code for those two specific classes:
http://gwt-widget.sourceforge.net/docs/xref/org/gwtwidgets/client/util/WindowUtils.html
http://gwt-widget.sourceforge.net/docs/xref/org/gwtwidgets/client/util/Location.html

Besides the usual information it will also parse the query string,
allowing access to parameters individually or as a Map.

Rob
http://gwt-widget.sourceforge.net
http://roberthanson.blogspot.com

ake...@gmail.com

unread,
Jul 19, 2006, 7:59:34 AM7/19/06
to Google Web Toolkit
Awesome, thanks! Will check that out.

Scooter

unread,
Jul 20, 2006, 10:29:53 PM7/20/06
to Google Web Toolkit
I have tried to get the ability to read parameters via the WindowUtils
and Location code. No problem doing a getHost and having the expected
value.

>From the Google app tried the following
http://localhost:8888/docimage.View?id=123456789

with this code

public void onModuleLoad() {
// loadingImage.setUrl("images/blanksearching.gif");
// Create an image, not yet referencing a URL.
try{
WindowUtils windowUtils = new WindowUtils();
Location location = windowUtils.getLocation();
System.out.println(location.getHost());
String id = location.getParameter("id");
String url = location.getPath();
System.out.println("path=" + url);
System.out.println("id=" + id);
// Point the image at a real URL.
lbl.setText("id=" + id);

}catch(Exception e){
System.out.println(e);
}


Any thoughts or examples on how to do this?

Scooter

unread,
Jul 20, 2006, 11:14:58 PM7/20/06
to Google Web Toolkit
Okay I found the problem with the URL. If you use the following it
works as expected.

http://localhost:8888/docimage.View/View.html?id=12345678

I do get the following text leaking out as part of the application when
using http://localhost:8888/docimage.View/View.html

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

Reply all
Reply to author
Forward
0 new messages