• 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

getInitParameter from a .war file

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
In my web application, I get db username and password from the web.xml file under the servletcontext directory. In its web.xml file, several init-params are declared. Now, I want to distribute this application in war format but web.xml file will go into that archive file and cannot be changed after archived.

Is there any way that I can get this info from outside the .war file? If so, can you give an example how to get it within the sevlet?
Thank you.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Murat,
You can put the db username and password in an external properties file instead of web.xml. Then it can be modified easily.
 
Murat Balkan
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
There is another web.xml file in the conf directory. How can I can parameter values from this file? conf.getInitParameter() will work here?
Thanks
 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Murat,
do not do this. Listen to Jeanne. This is the best way to do it, I think.
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An alternative is to use a DataSource with a set name (if this is for a database connection) or use JNDI with a set name.
Basically you want a method to get a value based on a key while not tying that value to an archive or format that should not be changed. An external Properties file, a DataSource configured at the app/web server level with a set name of a JNDI entry with a set name are all valid options.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only valid web.xml file is the one in the WEB-INF directory. Any other is just a regular file that happens to have the same name.
 
Murat Balkan
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok.I will use an external properties file.
Thank you all for your helps.
 
Enjoy the full beauty of the english language. Embedded in this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic