How to get URL in GWT?

732 views
Skip to first unread message

Vikas

unread,
Sep 8, 2009, 5:55:55 AM9/8/09
to Google Web Toolkit
For RPC communication, I need server IP address and port which is
specified in URL.
e.g. In 'http://10.4.6.131:8181/webClient.html' url 10.4.6.131 IP
address and 8181 port.

How to get this IP and port in GWT?

Thanks in advance,
Vikas

ThomasWrobel

unread,
Sep 8, 2009, 8:15:38 AM9/8/09
to Google Web Toolkit
I dont think theres a simple way, youd need to get the whole URL, look
between the second / and the 3rd /, then split the string around the
" : "

IP = UrlString.split(":")[0];
Port = UrlString.split(":")[1];

hezjing

unread,
Sep 8, 2009, 8:21:26 AM9/8/09
to google-we...@googlegroups.com
Hi Vikas,

How about retrieve the HttpServletRequest instance, then getLocalAddr() and getLocalPort()?

You may want to check out the rest of the useful getter methods in HttpServletRequest.

--

Hez

Raphael André Bauer

unread,
Sep 8, 2009, 8:35:50 AM9/8/09
to google-we...@googlegroups.com
On Tue, Sep 8, 2009 at 11:55 AM, Vikas<vikas....@gmail.com> wrote:
>
> For RPC communication, I need server IP address and port which is
> specified in URL.
> e.g. In 'http://10.4.6.131:8181/webClient.html' url 10.4.6.131 IP
> address and 8181 port.
>
> How to get this IP and port in GWT?
this native function might help:

public static native String getURL() /*-{
return $wnd.location.href;
}-*/;

cheers,
r

>
> Thanks in advance,
> Vikas
>
> >
>

Alexander Cherednichenko

unread,
Sep 8, 2009, 10:33:03 AM9/8/09
to Google Web Toolkit
I'd get it on the host page (in servlet env) and then accessed via
local variable in client code.

On Sep 8, 3:35 pm, Raphael André Bauer <raphael.andre.ba...@gmail.com>
wrote:

Thomas Broyer

unread,
Sep 8, 2009, 12:41:02 PM9/8/09
to Google Web Toolkit


On 8 sep, 11:55, Vikas <vikas.m.ya...@gmail.com> wrote:
> For RPC communication, I need server IP address and port which is
> specified in URL.
> e.g. In 'http://10.4.6.131:8181/webClient.html'url 10.4.6.131 IP
> address and 8181 port.
>
> How to get this IP and port in GWT?

Window.Location.getHostName() and Window.Location.getPort() ?

Vikas

unread,
Sep 9, 2009, 1:19:25 AM9/9/09
to Google Web Toolkit
Thanks to all of you for your help.

Window.Location.getHostName() and Window.Location.getPort() is working
fine for me :)


On Sep 8, 9:41 pm, Thomas Broyer <t.bro...@gmail.com> wrote:
> On 8 sep, 11:55, Vikas <vikas.m.ya...@gmail.com> wrote:
>
> > For RPC communication, I need server IP address and port which is
> > specified inURL.
> > e.g. In 'http://10.4.6.131:8181/webClient.html'url10.4.6.131 IP
Reply all
Reply to author
Forward
0 new messages