aspose file tools*
The moose likes Servlets and the fly likes Identifying geographic location of client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Identifying geographic location of client " Watch "Identifying geographic location of client " New topic
Author

Identifying geographic location of client

Arun Prasath
Ranch Hand

Joined: Sep 17, 2003
Posts: 192
Hi,
I am having two static pages that needs to be shown to clients depending upon the location where they are from. For requests coming from US, the first page should be shown. And for requests that is coming from other parts of the world, I would like to show different page.

How do I do this in a web application?
thanks in advance
s.arun prasath


SCJP 1.4, SCDJWS , SCJA<br />I can do ALL things through CHRIST who strengthens me.
haitham raik
Greenhorn

Joined: Aug 08, 2004
Posts: 17
there are two solutions:
- the first one: ask the user about his country then display the appropriate page depending on his answer.

- the second solution is using the following code:
Locale userLocale = request.getLocale();
if(userLocale.getCountry().equalsIgnoreCase("US")){
//display US Page
}else{
//display the other page
}

but remeber that the getLocale() method may return null or return the server Locale depending on the Servlet Container Implementation. so, you can not depend on the second solution.


Haitham Raik<br />SCJP 1.4 SCWCD 1.4 SCBCD 1.3 SCJA 1.0
Susanta Chatterjee
Ranch Hand

Joined: Aug 12, 2002
Posts: 102
method will return default locale for the server, if only the client request does not provide an Accept-Language header.

AFAIK, all the major browsers send this information correctly and client request contains this information.

Susanta
[ November 24, 2004: Message edited by: Susanta Chatterjee ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Of course none of this will tell you the geographical location of a client. You could have a Spanish speaker using a machine in Japan for example. Accept-language headers for that scenario will be requesting Spanish, not Japanese.

You can lookup IP addresses to find client location with varying degrees of success/accuracy, but this is more work than is necesary IMHO. Just ask the client to tell you explicitly and act accordingly.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Arun Prasath
Ranch Hand

Joined: Sep 17, 2003
Posts: 192
Originally posted by Paul Sturrock:
Of course none of this will tell you the geographical location of a client. You could have a Spanish speaker using a machine in Japan for example. Accept-language headers for that scenario will be requesting Spanish, not Japanese.

You can lookup IP addresses to find client location with varying degrees of success/accuracy, but this is more work than is necesary IMHO. Just ask the client to tell you explicitly and act accordingly.


Thanks Everybody for the response.
Yes, I came to a conclusion that I will ask for user's location initially. After getting his answer, store it in a cookie in his machine. Next time onwards retrieve his preference from cookie and show the page accordingly.

as, thats how www.cricinfo.com works...
thanks guys..
 
Don't get me started about those stupid light bulbs.
 
subject: Identifying geographic location of client