0

I would to internationalize my web app for multiple locales.

I've found several examples, like this.

They work, but in that cases it is displayed always the same page (that is if the user changes the language in any page, he/she is redirected to the home page for example).

I would that if the user clicks on a country flag (the html:link code is in a jsp file included by all the others jsp), the page (in which the user is) is reloaded. How could I do?

Sefran2
  • 3,578
  • 13
  • 71
  • 106

1 Answers1

1

Your example link is clear: When the country flag is selected, the link goes to your "LanguageAction", set the Locale like this:

request.getSession().setAttribute(Globals.LOCALE_KEY, Locale.FRANCE);

Finally, redirect the page back to the last viewed page. This will require you get the request URL before changing Locale.

I hope this helps.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
  • So I have not to use `return mapping.findForward("success");`, have I? Could you give a redirect example or a link? Thanks in advance. – Sefran2 Dec 28 '12 at 12:08
  • Look at Struts [`ActionRedirect`](http://struts.apache.org/1.x/struts-core/apidocs/org/apache/struts/action/ActionRedirect.html) (which extends `ActionForward`). [Example](http://javahelpline.wordpress.com/2012/09/05/forwarding-to-action-with-url-parameter-in-struts/). – Buhake Sindi Dec 28 '12 at 12:16
  • I save the url before setting the locale with `request.getHeader("Referer")` and then I use `return new ActionRedirect(url)`. It works, but I don't obtain the wished result, if the jsp page is the result of a servlet execution or if the params are passed via post. Should I get the url in another way or?. – Sefran2 Jan 05 '13 at 17:16