Home Answers Viewqa Java-Beginners How to get country locale from a http request

 
 


Mallesham
How to get country locale from a http request
5 Answer(s)      8 months ago
Posted in : Java Beginners

Hi,

I Have a requirement like , i need to get the country locale(from whcih country he is logged in) when user login to a web application. Based on that country locale i am going to implement business logic.

Can anyone help me out to get this done.

any help would be highly appreciated.

Thanks Katnam

View Answers

October 9, 2012 at 12:24 PM


Locale l = InetAddressLocator.getLocale(request.getRemoteAddr());
String countryName = l.getCountry();
String language = l.getDisplayLanguage();
String host = request.getRemoteHost();

    System.out.println("your IP address: "+InetAddressLocator.getLocale(request.getRemoteAddr()));   
System.out.println("your country name: "+countryName);  
    System.out.println("your language name: "+language);  
    System.out.println("your host name: "+host);

October 9, 2012 at 12:43 PM


could you please let me know what exactly InetAddressLocator ?

where i will get this class?

Thanks.


October 9, 2012 at 3:47 PM


Here is a code of getLocale() example that displays the date in specific in locale.

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.Locale;
import java.text.DateFormat;
import java.util.Date;

public class DateLocale extends HttpServlet{

  public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    Locale locale = request.getLocale( );
    String date = DateFormat.getDateTimeInstance(
                                  DateFormat.FULL, 
                                  DateFormat.SHORT, 
                                  locale).format(new Date( ));

    out.println(date);
  }
}

October 9, 2012 at 3:57 PM


Here is a getLocale() example in java servlet.

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.Locale;

public class GetLocale extends HttpServlet{

  public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException
  {
      Locale locale = request.getLocale();
      String language = locale.getLanguage();
      String country = locale.getCountry();

      response.setContentType("text/html");
      PrintWriter out = response.getWriter();

      out.println(language + ":" + country);
  }
}

October 10, 2012 at 9:36 AM


Thank you all..









Related Pages:
How to get country locale from a http request
How to get country locale from a http request  Hi, I Have a requirement like , i need to get the country locale(from whcih country he is logged in) when user login to a web application. Based on that country locale i am going
Get current country from iPhone ??
Get current country from iPhone ??  hello, I want to get the current country in the iPhone settings. Can anyone tell me how to get the current... for NSLocale* current_Locale = [NSLocale currentLocale]; NSString* country
JavaScript XML Http Request
JavaScript XML Http Request  ...;, url, true) to make a GET request for the given url 'data.xml'. It provides... how to access XML file with an XMLHTTP object using JavaScript
JMeter HTTP request example
JMeter HTTP request example  Concerning: http://www.roseindia.net/jmeter/using-jmeter.shtml how do I set path? also what do i need to do to get the helloworld servlet work? Thanks in advance
How to fireup HTTP request from JavaFX Client
How to fireup HTTP request from JavaFX Client  Please tel me how do I can fire HTTP post request from an JavaFX client. Sceneario: I've an JavaFX... i've working version of JSP Code to handle HTTP post request tested by posting
Java Locale
Java Locale  How will you load a specific locale?   Hi Friend, A locale is the part of a user's environment that brings together.../java/javadate/locale-format.shtml http://www.roseindia.net/tutorial/java
JSP Locale
illustrate you how to get the locale from the jsp page. The locale.jsp include a page... JSP Locale          JSP Locale is used to get the preferred locale
Java Servlet : Http Request Headers
Java Servlet : Http Request Headers In this tutorial, you will learn how to Http Request Headers works in java servlet. Http Request Headers : HTTP Request Header is a request line text that a HTTP client(eg. web browser)sends
Java get System Locale
Java get System Locale       In this section, you will learn how to obtain the locale. We are providing you an example which will obtain the locale of the system
Java Locale
country to country. To know more about this, just click:  http... Java Locale         A locale class in java api represents a specific geographical, political
How to send the request and get the request?
How to send the request and get the request?  how to send a request to a JSP file in another domain in the same server and get the request done i.e how to include JSP file of one domain to another doamin JSP within in the same
Retrieve HTTP Request Headers using JSP
the request headers. When a HTTP client sends a request, it is required to supply GET... Retrieve HTTP Request Headers using JSP   ...-Alive value or gets a  request line indicating HTTP 1.1, it may
Formatting and Parsing a Number for a Locale
Formatting and Parsing a Number for a Locale In this section, you will learn how to format and parse a number for a Locale. Formatting converts a date, time, number, or message from its internal representation into a string. Parsing
Locale in Spring MVC
=fr_FR to set the locale to French and get the message from French properties... SessionLocaleResolver resolves the locales by using a locale attribute from the session... locale by a configurable request parameter on every request of the user
How Can I get ArrayList of Data from jsp with ajax request
How Can I get ArrayList of Data from jsp with ajax request  Hi, I retereved 5 Employee Record of Data from Struts Action class to jsp with ajax response. But I don't how how can reterve this dynamic 5 employee records
Get Parameter Name From Servlet Request
Get Parameter Name From Servlet Request       This example illustrates about how to get parameter from jsp page... having name as firstname, lastname and middle name. We can get values
Java get System Locale
Java get System Locale       In this section, you will learn how to obtain the locale. We are providing you an example which will obtain the locale of the system by using
can u plz explain the http request methods - JSP-Servlet
can u plz explain the http request methods  can u plz explain http request methods? as well in jdbc...how to delete the duplicate records in database... ServletRequest Extends the ServletRequest interface to provide request information
HTTP Status 405 - Request method 'GET' not supported. Its urgent
HTTP Status 405 - Request method 'GET' not supported. Its urgent  ...') in onclick method, following error is displaying in new window. "HTTP Status 405 - Request method 'GET' not supported." Anybody reply ASAP, its urgent
GET and POST Method of HTTP
GET  and POST Method of HTTP       GET The Get is one the simplest Http method. Its main job... page, a sound file, a picture file (JPEG) etc. We can say that get method
Request Parameters in JSP
parameters. Request Parameters are the data sent from client to the server side... Request Parameters in JSP       In this section, you will study about the various request
Request Headers in JSP
Request Headers in JSP          Whenever an http client sends a request, it sends the request in the form of get or post method or any other HttpRequest 
What is Locale - Java Beginners
the following links: http://www.roseindia.net/java/javadate/locale-format.shtml http...What is Locale  Hi, What is Locale? Write example to show the use of Locale. Thanks   Hi Friend, A locale is the part
How to get xml file form http port using web service
How to get xml file form http port using web service  hi I am suresh i am using netbeans 6.9 to develop a web service for getting xml from http port... struck with getting xml file. How to access xml file in web service? Please Help
HTTP Protocol
the communication generally takes place over a TCP/IP protocol. HTTP Request Methods: 1) GET Method: The Get method is used to getting the data from the server. Get method... is appended along the request object, they do not get appended in the URL, so
How to Make HTTP Requests Using Curl and Decoding JSON Responses in PHP
etc. By using Curl library, You can make http request to a server and get...How to Make HTTP Requests Using Curl and Decoding JSON Responses in PHP .... As a php developer, sometimes we need to get data from other server or need
How to get the request scope values? - Struts
How to get the request scope values?  Get value in Struts
Setting the default Locale
Setting the default Locale       This section shows you how to set the default locale. Example presented in the section, illustrates you how to get and set the default locale
HTTP Status 500 -
attempt to load a JSP file from my Apache Tomcat server I get the error below... encountered an internal error () that prevented it from fulfilling this request...HTTP Status 500 -   I've installed my Java libraries, and I am
Locale Specific Date validations through JavaScript/Ajax...
MY Field!"; If(lanuage="Denmak"){ //You can even Get this value from...Locale Specific Date validations through JavaScript/Ajax...  Hi, I....), how to manipulate date validations through JavaScript or Ajax? Thanks
getHeader() Method Of The Request Object
form later for getting the value of the value of the HTTP header from if one by one... getHeader() Method Of The Request Object  ... illustration about the getHeader() method of the request object. Here, you will learn
JSP Request Object
an HTTP request. The request object is used to take the value from the client?s web browser and pass it to the server. This is performed using an HTTP request...JSP Request Object  JSP Request Object ?   request object
How will you load a specific locale? - Java Beginners
How will you load a specific locale?  HI, Please tell me how to load a specific locale in Java program. Thanks   Hi Friend, You... the following link: http://www.roseindia.net/tutorials/I18N/resource
Request Object In JSP
to the server by an HTTP request. Let if you submit the html form with some data to be send to the server, is received by the HTTP request object of the JSP. To access... the client browser to the server during an HTTP request object which most common use
JSP implicit object "request"
. The 'request' object takes the value from the web browser and pass it to the server. This is performed using an HTTP request such as: headers, cookies... the methods GET, POST, or PUT corresponding to the requested HTTP method used
Session Object from request
getting cookie object from request object? I know all methods are available its relevant class. is there any reason for getting session object from request , adding cookie object into response, getting object from request object. one
Check if parameter exists in servlet request
will see how to check is parameter exists in servlet request. In this example... methods to get object names from this Enumeration.    hasMoreElements... Check if parameter exists in servlet request
HTTP GET or POST for my AJAX call
HTTP GET or POST for my AJAX call  hello, Should I use an HTTP GET... GET request when retrieving data where the data will not change for a given request URL. An HTTP POST should be used when state is updated on the server
How to convert http website into Https from java?
How to convert http website into Https from java?  could any one tell me how to convert http website into Https from java
JSP Get Data From Database
JSP Get Data From Database In this section we will discuss about how to get data from database using JSP. To get data from database to a JSP page we... and put it into a result set. Then get all the data from the result set. Directory
HTTP Status 404 - /Login/userdetail.java
HTTP Status 404 - /Login/userdetail.java  I using netbeans to coonect...;head> <meta http-equiv="Content-Type" content="text/html; charset...; <body> <form name="f1" action="userdetail.java" method="get
How to get the values from the Combo Box - JSP-Servlet
How to get the values from the Combo Box   Sir, Actually i am getting the values in the combo box from table.I want what ever... ("Browser does not support HTTP Request") return } var url="getuser.jsp
Change language according to the locale
can load locale from the resource bundle that is suitable for the current user's... Change language according to the locale       This Example shows you how to change
request linux cd - Development process
request linux cd  how can i get free linux cd  well... you can find the details at http://www.roseindia.net/linux/ Services are available only in India. Thanx
Java get Http Headers
Java get Http Headers       In this section, we are going to illustrate you how to get... will get the Http Headers on the console. Download Source Code
The server encountered an internal error () that prevented it from fulfilling this request.
The server encountered an internal error () that prevented it from fulfilling this request.  when i run my code in eclipse i get the error... this request and http status error 404 also occurs. is there any problem in tomcat or mysql
The server encountered an internal error () that prevented it from fulfilling this request.
The server encountered an internal error () that prevented it from fulfilling this request.  when i run my code in eclipse i get the error... this request and http status error 404 also occurs. is there any problem in tomcat or mysql
How to get data from Excel sheet - Struts
How to get data from Excel sheet  Hi, I have an excel sheet with some data(including characters and numbers). Now i want read the data from... the following links: http://www.roseindia.net/tutorial/java/poi
Java get default Locale
Java get default Locale       Locale object is a representation of geographical, political, or cultural region. We can get and set our default locale through the java programs
Request header display in a jsp page
as an enumeration which can be iterated to get each of them. request_header_jsp.jsp <... with which this request was made, for example, GET, POST, or PUT -->... http://localhost:8080/user/request_header_jsp.jsp in address bar