I have created a class that extends PropertyMessageResources to read Property-Files from outside the Webapplication called MyMessageResources. It works fine. Now I want to store the url or the Path in web.xml like this:
<context-param> <param-name>LOCATION_EXT_MSG_RES</param-name> <param-value>http://localhost:8080/bundles</param-value> <description>Location for external Message-Resources</description> </context-param>
How can access this value inside the new class MyMessageResources?
you can read the web.xml when your app starts, and then give the parameter you want to MyMessageResources (call a constructor or a setter).
Alfredo Delgado Sanchez
Joined: Jul 19, 2007
can you please explain me a little more? I haven't enough experience with Struts. Please help me with this topics:
- Where should I put the code to read the property from web.xml and set to MyMessageResource? You say "when your app starts". Should I extends a class? Which place is this?
- It means that after the MessageResourceFactory creates MyMessageResources I should read the value from the web.xml and set this value on MyMessageResources, right? Should I write my own code to read the web.xml file? When no, hoy can I read on this context (start from app) the web.xml file?
I'd suggest you use an environment vaiable rather than a context parameter. To access a context parameter, you have to have a reference to the ServletContext object, while you can access an environment variable from any class as long as it's runnning in the web application. Example:
code in MyMessageResource (probably in the constructor)