Solved

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

Posted on 2006-07-12
5
2,822 Views
Last Modified: 2008-03-17
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
      <context-param>
          <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
          <param-value>resources.messages</param-value>
      </context-param>
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?

Thanks
0
Comment
Question by:NHBFighter
5 Comments
 
LVL 16

Expert Comment

by:suprapto45
ID: 17096091
You can use fmt:setBundle, can't you?

David
0
 
LVL 3

Expert Comment

by:anumalas
ID: 17097125
Hi

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

http://www.laliluna.de/struts-message-resources-tutorial.html

Hope this will help :)
0
 
LVL 4

Author Comment

by:NHBFighter
ID: 17098735
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.


Thanks
0
 
LVL 14

Accepted Solution

by:
boonleng earned 250 total points
ID: 17099693
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.

Regards,
Boon Leng
0
 
LVL 4

Author Comment

by:NHBFighter
ID: 17099769
Thanks boonleng
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JSP Popup page 2 106
java.util.concurrent.Callable way of creating threads 2 102
rebasing and merging used in SCM 1 66
build fail in maven project 11 179
OpenVPN is a great open source VPN server that is capable of providing quick and easy VPN access to your network on the cheap.  By default the software is configured to allow open access to your network.  But what if you want to restrict users to on…
When converting a physical machine to a virtual machine using VMware vCenter Converter Standalone or vCenter Converter Enterprise, if an adapter type is not selected during the initial customization the resulting virtual machine may contain an IDE d…
A short film showing how OnPage and Connectwise integration works.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now