Changing default locale of struts2

2019-08-04 07:40发布

How can I modify struts2 default locale specified in struts.properties file as struts.locale ?

The default locale is "en" and i need to change it to "en_Us"

I tried as follows

<constant name="struts.locale" value="en_US" />

in my struts.xml file.

1条回答
再贱就再见
2楼-- · 2019-08-04 08:21

I know this is late answer, but at someday somebody will find it as what he or she was looking for for long time.

The Struts2 framework sets the default locale based on language preferences of a browser, that is, it looks at Accept-language request header, and if not finding it then go to the struts properties for this.

So, if you want to change to the locale en_US, then you should set it in the browser parameters, set as first prefered language.

If you want to change this behavior, you may write interceptor which will set needed locale for the ActionContext. Here reference to the API http://struts.apache.org/maven/struts2-core/apidocs/com/opensymphony/xwork2/ActionContext.html#setLocale(java.util.Locale) Don't forget to put your interceptor in the interceptors stack in the struts.xml file.

Tutorial about creating your own interceptors: http://www.tutorialspoint.com/struts_2/struts_interceptors.htm

Hope, it will help somebody.

查看更多
登录 后发表回答