How to change locale in Struts2 from database

i need to change the language of the user from the database, so to do this all in need is to set “request_locale”, see example. if i put this code below in my, then dutch will be my default language

struts.locale = du_NL

a user can also change language, so i have to save the language settings in database, so that next time when the user logs in, he/she will get his/her language instead of the default one. to do this i have added “param” in my struts.xml

<result name="success" type="redirectAction">
                <param name="actionName">myAction</param>
                <param name="request_locale">${userLang}</param>

“userLang” is what i have set from the action i.e. en, du or fr. once the “request_locale” is set the page will be displayed as per the “userLang”. we can see this by using the code below


because myAction.action?request_locale=en_US or myAction.action?request_locale=du_NL etc will set the locale in user session. i must say struts2 is really cool.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: