• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getInitParameter from a .war file

 
Murat Balkan
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • 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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Scott Duncan
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Murat,
do not do this. Listen to Jeanne. This is the best way to do it, I think.
 
Ken Robinson
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • 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
Marshal
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Ok.I will use an external properties file.
Thank you all for your helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic