File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes how to get the client's bowser URL who's hitting your service from ajax call? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to get the client Watch "how to get the client New topic
Author

how to get the client's bowser URL who's hitting your service from ajax call?

subodh gupta
Ranch Hand

Joined: Jul 23, 2007
Posts: 203
I have a service which is being hit by a ajax call from the client i need to know there web address is there any way to do this?


http://subodh-gupta.blogspot.com
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

check the referer HTTP header
http://en.wikipedia.org/wiki/HTTP_referrer

This value is not 100% correct since clients can block or fake it, but it is your best and easiest guess.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
javax.servlet.ServletRequest#getRemoteAddr()


Ping & DNS - my free Android networking tools app
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

The OP is asking for the browser URL, not the client external IP
subodh gupta
Ranch Hand

Joined: Jul 23, 2007
Posts: 203
@Ulf i am not looking for IP

@David this is not fool proof so many a times i might get nothing
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Do you also provide the JS that creates the Ajax call? you could use that to get the client URL and return that value in the the Ajax payload. People may not like it and could consider it 'snooping'.
Personally I'd stick with the referer unless it was proven to be unreliable.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
subodh gupta wrote:@Ulf i am not looking for IP

I see. "web address" *can* mean the IP address, though.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Yeah, "web address" is pretty ambiguous.

In any case, why do you need this? Maybe there's another way to solve the proble.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to get the client's bowser URL who's hitting your service from ajax call?