Using resource bundle in Struts2 interceptors

jakarta-ee, java, struts2, web

Solution

Your can use the `java.util.ResourceBundle` class.

ResourceBundle bundle = ResourceBundle.getBundle("my_resource_name", locale);
bundle.getString("resource_key");

Problem

Struts2 Actions normally extend `ActionSupport` class which implements of `TextProvider` interface and provides access to resource bundle files in a convenient way using `getText()` method. I want to use resource bundle in Interceptors. I guess I have to copy `TextProvider` implementation and paste it in my interceptor. I have already defined global recourse file in `struts.xml` ``` <constant name="struts.custom.i18n.resources" value="resources.global" /> ``` And place `global.properties` in `resources` package. It works fine in Action Classes Is there any easier way to use resource bundle in interceptors?

Original source