Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I obtain the message resources object in a servlet?

I'm developing a project with Struts and I was wondering if it's possible to get the message resources object in a servlet, which is included in the same project.

There's no possibility to get that object with the method getResources(HTTPServletRequest) because the servlet does not extends an Action class. Is there a way to do it?

Thanks in advance.

like image 775
Carlos Pastor Avatar asked Oct 20 '09 07:10

Carlos Pastor


1 Answers

Well, I finally found how to do it. Just if somebody gets stuck in the same issue, here's the solution: use the java.util.ResourceBundle class in your servlet.

You just have to create the ResourceBundle passing along the name of the properties class and the locale you want to use, like you can see below:

ResourceBundle rb = new ResourceBundle("com.foo.package.theClass", myLocale);
//And then get the messages from the rb object
rb.getMessage("myPropertiesKey");
like image 118
Carlos Pastor Avatar answered Oct 31 '22 23:10

Carlos Pastor