I have JSTL Java code that reads request header Accept language paremeter
<c:set var="locale" value="<%= request.getHeader("Accept-Language") %>"/>
The variable locale's value varies based on the order of browser's language setting.
Sometimes it is like this
en-GB,en;q=0.8,en-AU;q=0.6,en-US;q=0.4,en-CA;q=0.2
Some other times it is like this
en,en-GB;q=0.8,en-AU;q=0.6,en-US;q=0.4,en-CA;q=0.2
On either case I want to read the first occurrence of locale such as en-XX. In this case, en-GB.
I was using split function but I couldn't figure out the correct way to use it for this task.
I did this and it'd work only if en-XX was the first one in the string
<c:set var="locale" value="<%= request.getHeader("Accept-Language").split(",")[0] %>"/>
Any help in terms of incorporating regex with split function (or anyother function) is much appreciated.
Thanks,
${header['name']}and the request locale is just available by${pageContext.request.locale}.