I need to parse GET parameter

259 views
Skip to first unread message

Will

unread,
Oct 17, 2007, 4:21:31 PM10/17/07
to Google Web Toolkit
In my application, there are personal pages for each user. And each
user wants a different urls for the page. It would be very easy to use
parameters of GET request like xxxx.jsp?id=111111 to generate urls.


But how can GWT parse the GET request parameters?
or how to solve this kind of problem?

David Given

unread,
Oct 17, 2007, 5:11:18 PM10/17/07
to Google-We...@googlegroups.com
Will wrote:
> In my application, there are personal pages for each user. And each
> user wants a different urls for the page. It would be very easy to use
> parameters of GET request like xxxx.jsp?id=111111 to generate urls.

Look into History and HistoryListener. When your page is loaded, any history
token after a # will be automatically handed to your app. So your URLs will
look like xxxx.html#1, xxxx.html#2, etc.

--
┌── dg@cowlark.com ─── http://www.cowlark.com ───────────────────

│ "There does not now, nor will there ever, exist a programming language in
│ which it is the least bit hard to write bad programs." --- Flon's Axiom

Levi Purvis

unread,
Oct 17, 2007, 6:43:21 PM10/17/07
to Google Web Toolkit

If you host your GWT module in a JSP page, you can use normal JSP code
to grab the parameter -- request.getParameter("foo"). This mainly
works well for initial or startup parameters.

You can then stick the parameter into a JavaScript structure and
access the structure through the GWT Dictionary class. You could
generically add them all in a loop, too.

Example JSP code:

<body>
<%
String foo = request.getParameter("foo");
if (foo == null || foo.trim().length() == 0) {
foo = "default";
}
%>

<script language="javascript">
var parameters = {
foo: "<%=foo%>"
};
</script>

<script language="javascript" src="my.gwt.Module.nocache.js"></
script>
</body>


Example Java code:

Dictionary parameters = Dictionary.getDictionary("parameters");
String foo = parameters.get("foo");

Pavel Byles

unread,
Oct 17, 2007, 7:31:05 PM10/17/07
to Google-We...@googlegroups.com
I had this same issue.  I'm sure GWT can do this since it reads the locale param from the URL string.

I used native javascript to get the params:

private native String getParamString() /*-{
        return $wnd.location.search;
}-*/;

Then you can call it by:
String getStr = getParamString();
// now you can parse this string into it's key/value pairs by splitting the string by ampersands then by equal signs.

Hope this helps.
Reply all
Reply to author
Forward
0 new messages