• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing parameter from web.xml inside a MessageResource class

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Alfredo Delgado Sanchez
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic