Using MessageResources in Struts

MessageResources allows you to internationalize your application by defining fields and their values in a global file and accessing them elsewhere in the application.

This is a simple example of how you can use MessageResources.

1. Create a file, say “ApplicationResource.properties” in your package, say at “com.michaelfernando.resource” and type the following into this new file:

application.version=Beta Ver 0.1 Build 22

2. Add this element in your “struts-config.xml” file if it doesnt exist:

<message-resources parameter=”com/michaelfernando/resource/ApplicationResource”/>

3. In your Java Action Class, access the field by writing the following:

MessageResources resource = getResources(request);

String version = resource.getMessage(“application.version”);

Thats it!!!

Tags: ,

No comments yet.

Leave a Reply