This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes How to Allow User to Select a Locale Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to Allow User to Select a Locale" Watch "How to Allow User to Select a Locale" New topic
Author

How to Allow User to Select a Locale

Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
Normally, ActionServlet with check the 'Accept-Language' header of the http request message and from it determines automatically the locale of the client browser. Struts will then select the appropriate message resource from this auto obtained locale.

However, this approach requires the browser config'ed with the proper accept-language header (for IE tool->option->language). Inside of this, I want to put the locale selection in a JSP page and ask the user to select it explicitly.

My problem is how I can tell the ActionServlet what locale the user has selected in my JSP page. Since most of the locale selection is done automatically, I do not quite understand how Struts is handling this and the way to override it.

Could anyone get me some advice. Thx
Franck Tranchant
Ranch Hand

Joined: Aug 07, 2003
Posts: 75
Hi

Locale can be changed manually using Action's setLocale(HttpServletRequest, Locale) method.

Just use the lowercase two-letter ISO-639 language code and the uppercase two-letter ISO-3166 country code to build a locale then use the setter to modify the user's current selected Locale into it's Session.


Franck<p>--------------------
 
Consider Paul's rocket mass heater.
 
subject: How to Allow User to Select a Locale
 
Similar Threads
Struts: The Complete Reference - Internationalizaion ???
Internationalization with dropdown
Dummy needs explanation
Best practice for i18n/locale selection?
User to Choose Language Explicitly