| Author |
Accessing parameter from web.xml inside a MessageResource class
|
Alfredo Delgado Sanchez
Greenhorn
Joined: Jul 19, 2007
Posts: 10
|
|
Hello, 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? Best Regards ADS
|
 |
Herman Schelti
Ranch Hand
Joined: Jul 17, 2006
Posts: 387
|
|
hi, 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). Herman
|
 |
Alfredo Delgado Sanchez
Greenhorn
Joined: Jul 19, 2007
Posts: 10
|
|
Hello, 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? Many thanks Best Regards ADS
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
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: web.xml code in MyMessageResource (probably in the constructor)
|
Merrill
Consultant, Sima Solutions
|
 |
Alfredo Delgado Sanchez
Greenhorn
Joined: Jul 19, 2007
Posts: 10
|
|
Hello, I used the <env-entry> from web.xml and works fine. I haven't test it, but I read that if some changes will do in web.xml this kind of entries will not be updated. A Tomcat-Server restart is needed. Many thanks and Best Regards ADS
|
 |
 |
|
|
subject: Accessing parameter from web.xml inside a MessageResource class
|
|
|