Struts2 Resource Bundles and Localization Example

Struts2 framework supports internationalization and we can create resource bundle property files to be used by the framework. Struts2 i18n is used a lot in creating labels based on the locale in result pages using UI tags or to show action messages or errors when action classes implement ValidationAware interface or extend ActionSupport class.

Struts2 framework supports i18n through I18nInterceptor interceptor and we can pass locale in request with parameter request_locale. This interceptor is part of defaultStack interceptor stack, so we don’t need to do anything for localization. However we can override locale request parameter with parameterName parameter, we will look into this in our sample project.

When we pass localization key, Struts 2 framework looks for resource bundles at various places in below order:

  • {ActionClassName}.properties and it should be in the same package with Action Class.
  • (every interface and sub-interface)
  • (all the way to
  • ModelDriven’s model (if implements ModelDriven)
  • in the class package and then to the parent packages till the root
  • global resource properties configured in struts property file

It’s good to have options but excessive options can lead to confusion. Also if we have so many property files for localization, it will add IO cost in searching the keys into them. Personally I always create only package and global properties files but sometimes when we need to show message specific to an action class, action class property files come handy.

We can get localized text by following options:

Above method can be used when action class is extending ActionSupport class, getText() method is defined in ActionSupport class.

We can use Struts text tag to get the localized string, if the key is not found then “Default Text” will be used.

We can use i18n tag to specify the location of resource bundle from where the properties will be loaded. In above case, it will try to get key value from from WEB-INF/classes directory. If we know the location of keys, then it’s good to use i18n tag for better performance.

Most of the UI tags have key attribute that we can use to get the localized text from resource bundle.

Let’s look into a simple web application where we are using Struts2 resource bundle and i18n support for generating localized response. Our final project will look like below image.


For our example, we will have localized texts for fr_FR and de_DE locales and we have ActionClass, package and global resource bundles. As you can see from above image that Action Class property files are in the same package whereas package property files are in the parent package. Global resource bundles are in the classes directory and we will configure it in struts configuration file.

Configuration Files



Deployment descriptor and maven pom.xml files are simple and used to configure web application to use Struts2 framework.


We are providing global resource bundle name as global and overriding the i18n interceptor locale request parameter to appLocale, we will use this in our request form parameters for our use case.

Action Class

Action class is simple and have only few java bean properties with getter and setter methods.

Resource Bundles

Global Resource Bundles

Package Resource Bundles

Action Class Resource Bundles

JSP Pages


As you can see that we can provide locale from the select box in home.jsp and the variable name is same as configured in struts property file for locale parameter.


welcome.jsp is showing usage of localization keys through i18n, text and property tag.

Now when we run our application, we get following response pages.


That’s all for Struts2 internationalization and resource bundle example, it’s very simple and easy to use. Make sure you have properly designed the application resource bundles otherwise it will become hard to maintain if the number of files are too much.

Download project from below link and play around with it for better understanding.

By admin

Leave a Reply

%d bloggers like this: