Here are two classes that can be used to get at the values in the
command line:

import com.google.gwt.core.client.JavaScriptObject;

/**
 * Thanks to Robert Hanson and Adam Tacy for "GWT in Action".
 */

public class CommandLine extends JavaScriptObject {

    private static CommandLineImpl impl = new CommandLineImpl();

    protected CommandLine() {
    }

    public static final String getArg(String key) {
        return impl.getArg(key);
    }

}

//+++++++++++++++++++++++++++++++++

public class CommandLineImpl {

    /**
     * Javascriptcode thanks to Scott Burton and "lobo235"
     */
    public native String getArg(String name) /*-{
            name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
            var regexS = "[\\?&]"+name+"=([^&#]*)";
            var regex = new RegExp( regexS );

            var results = regex.exec( $wnd.location.href );

            if(results == null)
            {
                return "";
            }
            else
            {
                return results[1];
            }
    }-*/;

}


Then in your entry point you have a call like this:

String value1 = CommandLine.getArg("key1");


On Feb 6, 12:02 pm, OffTheWall <move-o...@comcast.net> wrote:
> I would like my GWT application to parse the url that it was called
> with.  Something like this:
>
> http://mymachine.com/myapp?key1=value1
>
> And be able to grab the key values pairs from within my application.
> The key may be a fixed value, and the value of course will change with
> invocation of my application.  Can anybody help me with this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to