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.
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With