Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Identifying geographic location of client

 
Arun Prasath
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
haitham raik
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Susanta Chatterjee
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arun Prasath
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic