How to get the resource bundle from the context like the fmt:message tag does

Hi all

I'm creating an app that is using the <fmt:message> tag to display language specific text in my JSP pages.
I configure my app for this by adding this to the web.xml file
I want to get get access to the same set of resource bundles that the fmt tag does from with in the applications java code. Does any one know how to do that?

Who is Participating?
boonlengConnect With a Mentor Commented:
In the servlet, get the context parameter value to initialise the resource bundle.

String name = getServletConfig().getServletContext().getInitParameter("javax.servlet.jsp.jstl.fmt.localizationContext");
ResourceBundle res = ResourceBundle.getBundle(name);

You can even load the resource bundle to a singleton class from a servlet (probably a startup server), then access the singleton class to retrieve the messages from any of the java code in the application.

Hope this help.

Boon Leng
You can use fmt:setBundle, can't you?


You can use struts message resources bundle to do the same with fmt tags . But you need use struts frame work in your application
You will get all the messages from the request parameter in your action class (java class)

For more information on messages resources please go thru follwing link

Hope this will help :)
NHBFighterAuthor Commented:
Thanks for the replies

I'm using Spring as the MVC framework to develop this application, I konw Spring has this messaging functionality built in as well. What I really want to know is how can I get access to the same resource bundle that the fmt tag uses from with in the java code of my application.  I don't mind using struts or spring for this but I want to know how to do it outside those frameworks.

I can only use the fmt:setBundle tag inside JSP pages so it doesn't help me get the bundle from with in the java code.

NHBFighterAuthor Commented:
Thanks boonleng
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.