JSP Locale is used to get the preferred locale of the user. A user can configure their browser with a US language locale ("en_US") as the preferred one. Apart from this user has configured their browser with various locales. It is designed in a way that returns a more readable name ("es_ES") for the locale.
Understand with Example
The Tutorial illustrate you how to get the locale from the jsp page. The locale.jsp include a page import directive that import a package "java.util.Locale". This Package define an object that represents a specific geographical, political, or cultural region. You can see in the given example that we have used the request.getLocale() method provided by the interface ServletRequest that will return the preferred locale based on the Accept-Language header.
request.getLocale ( ) : The method is used to return the current locale based on the Accept-Language header.
Here is the code of locale.jsp
|<%@ page import="java.util.Locale "%>
Locale l = request.getLocale();
out.println("Locale is :"+l);
Output will be displayed as:
Recommend the tutorial