#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    29
    Rep Power
    0

    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. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    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
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    29
    Rep Power
    0
    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/j...ceprofile.html

    Regards

    FK

IMN logo majestic logo threadwatch logo seochat tools logo