Load Message Resources from Struts Action
Sometime, you will need to read some text from the resource files in your application from the Struts Action class. The easier way which most developers are using is to open the resource file using the java.util.ResourceBundle class, which will open the file and read its content.
This will open the file for every request to your action! I am sure that it is very bad from the performance point.
Struts provide a methods in the Action class to get the locale and the resources
getLocale(request) and getResources(request)
For some reason, getResources() didnâ€™t work with me.
I didnâ€™t think about the first solution because I am sure that the resources are loaded in the application and must be stored somewhere, so, lets use. And here is the code
MessageResources resources = (MessageResources) getServlet().getServletContext().getAttribute(bundle); message = resources.getMessage(locale, key);
I hope that this can help somebody to tune the struts web application performance.