0

I would like to know if can get the language of a client operating system from a JSP and how to do it?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Platus
  • 1,753
  • 8
  • 25
  • 51

1 Answers1

2

You don't have access to the client's operating system, so your only choice is to rely on the information that is presented to you by the client browser.

The way that the browser presents information about language preferences to the server is by using the HTTP Accept-Language header.

Since the information in the Accept-Language header can be a little bit hard to parse, in JSP/servlets, you can use the ServletRequest.getLocales() method, which, according to the JavaDoc

Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header. If the client request doesn't provide an Accept-Languagheader, this method returns anEnumerationcontaining oneLocale`, the default locale for the server.

Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156