aspose file tools*
The moose likes Servlets and the fly likes getInitParameter from a .war file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "getInitParameter from a .war file" Watch "getInitParameter from a .war file" New topic
Author

getInitParameter from a .war file

Murat Balkan
Ranch Hand

Joined: Sep 10, 2002
Posts: 127
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30548
    
152

Murat,
You can put the db username and password in an external properties file instead of web.xml. Then it can be modified easily.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Murat Balkan
Ranch Hand

Joined: Sep 10, 2002
Posts: 127
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

Joined: Nov 01, 2002
Posts: 363
Murat,
do not do this. Listen to Jeanne. This is the best way to do it, I think.


No more rhymes! I mean it!<br /> <br />Does anybody want a peanut?
Ken Robinson
Ranch Hand

Joined: Dec 23, 2003
Posts: 101
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30548
    
152

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

Joined: Sep 10, 2002
Posts: 127
Ok.I will use an external properties file.
Thank you all for your helps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getInitParameter from a .war file