If you use spring security ,maybe this solution help you.
Internationalization config :
@Configuration
@EnableAutoConfiguration
public class InternationalizationConfig extends WebMvcConfigurerAdapter {
@Bean
public LocaleResolver localeResolver() {
SessionLocaleResolver slr = new SessionLocaleResolver();
slr.setDefaultLocale(new Locale("tr"));//Locale.forLanguageTag("tr"));//
// slr.setDefaultLocale(Locale.forLanguageTag("tr"));
return slr;
}
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
lci.setParamName("lang");
return lci;
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor());
}
}
Spring Security config:
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.exceptionHandling().accessDeniedPage("/login")
.and()
.formLogin().loginPage("/index")
.usernameParameter("username")
.passwordParameter("password")
.loginProcessingUrl("/j_spring_security_check")
.failureUrl("/loginFail")
.defaultSuccessUrl("/loginSuccess")
.and()
.logout().logoutUrl("/logout").logoutSuccessUrl("/index")
;
http.headers().frameOptions().disable();
}
}
Controller :
@Controller
public class LoginController {
@RequestMapping("/loginSuccess")
public String loginSuccess(){
User user = getUserFromDatabase;
return "redirect:/home?lang="+user.getLanguage();
}
}