This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
I'm trying to localize a page according to the language settings on the users browser .... thing is I need to know how to get hold of that information. I've heard there's an attribute called accept-language ... but I'm not sure how to get hold of it .. .can anyone help??
Pounding at a thick stone wall won't move it, sometimes, you need to step back to see the way around.
Joined: Mar 02, 2000
Don't worry I found the solution ... it took me so long cos I was looking at an old servlet API. Anyway for Servlets v2.2 you need to use the HttpServletRequest.getHeaders(String) method and pass in the name of the header .. which in this case is Accept-Language. this returns an Enumeration of the languages accepted by the browser.
I guess you used getHeader() like in the code given below
But how do i use this information of "Accept-language". could you throw more light.
[This message has been edited by Rahul Mahindrakar (edited January 24, 2001).]
Joined: Mar 02, 2000
First of all I used getHeaders(String) rather than getHeader(String) because as the Servlets 2.2 API says "Some headers, such as Accept-Language can be sent by clients as several headers each with a different value rather than sending the header as a comma separated list. ". So a method which returns an Enumeration rather than a String is more approriate. What is returned is an Enumeration of strings which look something like this. "en,en-gb;q=0.7,en-us;q=0.3" which you can compare to your browsers language settings. Basically this one says. "I'd prefer English (en), my next prefernce is British English(en-gb) and my next preference is US English(en-us)." I havn't quite completed what I'm doing yet but i'm hoping to be able to use these settings to localize a JSP according to the browser language settings rather than having the user specify a language.