Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to detect the territory of a request ?

 
Aryan The Bad Boy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to detect the territory of a request in Struts?

Is there any way to detect that this request is from US or india or any other country or territory ?
 
Pushkar Choudhary
Rancher
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aryan The Bad Boy wrote:

Please edit your name to use a real first and last name. See the Naming Policy for more details.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Servlets; not Struts-specific.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Aryan The Bad Boy", please check your private messages for an important administrative matter one final time.
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if there's a simpler way, but you can get the IP address of the remote host (from the request headers), then make use of an online resource for looking up information on the IP address. I don't know of any such service off-hand, but you should be able to Google and find something.

Hope this helps.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aryan The Bad Boy wrote:How to detect the territory of a request in Struts?

Is there any way to detect that this request is from US or india or any other country or territory ?


the complete way to do it is by using the remote user's IP address against a local or remote database
to get your own IP database that can differentiate countries based on IP, you can get a free GEO database at maxwind.com. To go beyond country, then you pay big money.

A remote service like Mark suggests will of course be easier and be able to tell you India vs United states.

Another way is to get the accept-charset and accept-language headers out of the request object and infer things from there. The request has a getLocale() method that uses the accept-language header to return the preferred locale. I don't know what the default language setting for India is. Obviously, this depends on the user's browser settings and they can easily change this.

you can also calculate the difference in hours between remote user's local time and GMT using Java Script

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic