Search code examples
springjakarta-eeinternationalizationlocale

How can Locale.setDefault(new Locale ("en", "US")) be changed at runtime?


I keep looking for the answer on how to reset/change the Locale of a Java (Spring) web application once it's set via the Locale.setDefault(new Locale ("en", "US")). Can someone please help me because it's frustrating seeing that after I set the Locale in my web app, I can't change it by simply calling Locale.setDefault(new Locale ("newLang", "newCountry")).

Is the locale being cached on the server?


Solution

  • The Locale.setDefault is a global thing. If you have two users that need to use different locales that won't work out.

    You should probably put the locale in the HttpServletRequest.getSession().

    After we did the global setDefault it even switched the language and logging of our application server.