I'm loading all my messages from a properties file using the JSTL fmt:message tags. But now I have a case where I need to load a message from the same file, but from a Struts Action class. How do I load a localized message from a properties file? I looked at ResourceBundle.getBundle, but I don't know how to specify the file. The API states that it must be a fully qualified class name, but where would it start looking for the file? In the WEB-INF/classes directory?
Hi, Code snippet to explain the example. String language = "en"; String country = "US"; Locale currentLocale; java.util.ResourceBundle messages; currentLocale = new Locale(language, country); messages = ResourceBundle.getBundle("MessagesBundle", currentLocale); System.out.println(messages.getString("greetings")); System.out.println(messages.getString("inquiry")); System.out.println(messages.getString("farewell")); MessageBundle.properties ======================== greetings = Hello. farewell = Goodbye. inquiry = How are you? Depending on the MessageBundle properties file, the output will vary. Now its upto u to code to retrieve the MessageBundle.properties file. Rgds, Seetesh
Joined: Jul 11, 2003
Thanks, I had that part. What I wanted to avoid was hunting around as to where it would start loading the resource from. It turns out it does base the path on WEB-INF/classes. Now if I can only get the user's locale, JSTL isn't setting a session attribute after determining the browser-based locale. Over to the JSP forum...