• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Identifying geographic location of client

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic