Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 30th, 2002, 12:31 PM
ebizsols ebizsols is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 29 ebizsols User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
  #2  
Old October 30th, 2002, 02:28 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
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

Reply With Quote
  #3  
Old October 31st, 2002, 09:07 AM
ebizsols ebizsols is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 29 ebizsols User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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/...rceprofile.html

Regards

FK

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Using XML files for storing application parameters


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT