
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

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);

could you please let me know what exactly InetAddressLocator ?
where i will get this class?
Thanks.

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);
}
}

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);
}
}

Thank you all..
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.