File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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

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

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.

I agree. Here's the link:
subject: How to Allow User to Select a Locale
It's not a secret anymore!