|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Using XML files for storing application parameters
Hi,
I have a problem understanding the concept of <context-param>. I want to write a file "carplan-config.xml" which will store things like: <carplan-config> <database> <driver>org.gjt.mm.mysql.Driver</driver> <uri>jdbc:mysql://localhost/myDB</uri> <username>fk</username> <password>fk</password> </database> <messages> <no-maintenance>...</no-maintenance> ... </messages> </carplan-config> I dont know how I would then read these in my application. Furhtermore, how do I write the code for reading the <context-param> <param-name>test</param-name> <param-value>a test</param-value> </context-param> I know I need to use the javax.servlet.ServletContext.getInitParameter() but not sure I how I would implement this. I have succefully managed to read the init values stored in the <servlet> tag in web.xml, using javax.servlet.ServletConfig.getInitParameter() Even if I could be pointed to the right direction for some reading on the subject it will be most appreciated. Apologies if teh question is too generic. Regards FK |
|
#2
|
|||
|
|||
|
Gah... This took me forever to find. I knew it was there, just not exactly where....
![]() Anyway, you're going to have to parse your configuration variable yourself. The method you're trying is only going to work with the dtd defined for the server.xml file. Anyway, there's an easier way than writing your own parser. http://jakarta.apache.org/commons/digester.html Apache project for parsing xml config files.
__________________
-james |
|
#3
|
|||
|
|||
|
Thansk for the direction, I am currently strugging thorugh the various example to understand how it works. I will try and put any comments here which may help other readers.
For anyone follwoing the thread, here is a better article on the Digester than one recommended on the Jakarat website: http://www.javaworld.com/javaworld/...rceprofile.html Regards FK |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Using XML files for storing application parameters |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|