Parse Accept-Language header in Java

Pushkar picture Pushkar · Jul 26, 2011 · Viewed 34k times · Source

The accept-language header in request is usually a long complex string -

Eg.

Accept-Language : en-ca,en;q=0.8,en-us;q=0.6,de-de;q=0.4,de;q=0.2

Is there a simple way to parse it in java? Or a API to help me do that?

Answer

Brett Kail picture Brett Kail · Jul 27, 2011

I would suggest using ServletRequest.getLocales() to let the container parse Accept-Language rather than trying to manage the complexity yourself.