Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How to detect the territory of a request ?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Rancher
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Servlets; not Struts-specific.
 
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Aryan The Bad Boy", please check your private messages for an important administrative matter one final time.
 
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

reply
    Bookmark Topic Watch Topic
  • New Topic